]>
git.r.bdr.sh - rbdr/grafn/blob - test/grafn.js
3 const Grafn
= require('..');
4 const Tap
= require('tap');
6 Tap
.beforeEach((done
, t
) => {
13 Tap
.test(async (t
) => {
15 await t
.rejects(t
.graph
.run('nonExisting'), 'It throws an error if you try to run a non-existing vertex');
18 Tap
.test(async (t
) => {
28 await t
.graph
.run('root');
29 t
.equal(t
.verticesRan
, 1, 'It runs a vertex if no dependencies are defined');
32 Tap
.test(async (t
) => {
36 dependencies: ['nonExisting'],
43 await t
.graph
.run('unfulfilled');
44 t
.equal(t
.verticesRan
, 0, 'It does not run a vertex if it has unfulfilled dependencies');
47 Tap
.test(async (t
) => {
55 name: 'firstDependent',
56 dependencies: ['root'],
64 name: 'secondDependent',
65 dependencies: ['root'],
72 await t
.graph
.run('root');
73 t
.equal(t
.verticesRan
, 3, 'It runs dependent vertices on completion of a vertex\'s action');
76 Tap
.test(async (t
) => {
84 name: 'firstDependent',
85 dependencies: ['root'],
93 name: 'secondDependent',
94 dependencies: ['root'],
103 dependencies: ['firstDependent', 'secondDependent'],
106 t
.verticesRan
= state
.firstDependent
+ state
.secondDependent
;
110 await t
.graph
.run('root');
111 t
.equal(t
.verticesRan
, 3, 'It ensures dependencies state is available before running dependents');
114 Tap
.test(async (t
) => {
125 name: 'stateDependent',
126 dependencies: ['root'],
129 t
.verticesRan
= state
.root
;
133 await t
.graph
.run('root');
134 t
.equal(t
.verticesRan
, 101, 'It gives dependent vertices a state including their dependencies\' results');
137 Tap
.test(async (t
) => {
143 throw new Error('Unexpected root problem');
147 await t
.rejects(t
.graph
.run('root'), 'It throws an error if a vertex throws an error');
150 Tap
.test(async (t
) => {
161 await t
.graph
.run('root');
162 await t
.graph
.run('root');
163 t
.equal(t
.verticesRan
, 1, 'It runs a vertex only once');
174 name: 'firstDependent',
175 dependencies: ['root'],
180 name: 'secondDependent',
181 dependencies: ['root'],
187 dependencies: ['firstDependent', 'secondDependent'],
191 t
.matchSnapshot(t
.graph
.toString(), 'It can convert to a string representing the graph in graphviz format');
195 Tap
.test('It colorizes the graph based on execution results', async (t
) => {
203 name: 'firstDependent',
204 dependencies: ['root'],
209 name: 'secondDependent',
210 dependencies: ['root'],
213 throw new Error('Second dependent has failed');
219 dependencies: ['firstDependent', 'secondDependent'],
223 await t
.rejects(t
.graph
.run('root'), 'It throws an error if a sub-step fails');
224 t
.matchSnapshot(t
.graph
.toString(), 'It adds the right colors according to execution');