react 0.0.3 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +6 -0
- package/Jakefile.js +8 -0
- package/README.md +226 -86
- package/examples/ast1.js +26 -0
- package/examples/chain-events1.js +34 -0
- package/examples/chain1.js +19 -0
- package/examples/default-events1.js +52 -0
- package/examples/default1.js +41 -0
- package/examples/fstr-events1.js +51 -0
- package/examples/fstr1.js +36 -0
- package/examples/pcode1.js +22 -0
- package/jake-tasks/jake-test.js +64 -0
- package/lib/base-task.js +115 -0
- package/lib/cb-task.js +67 -0
- package/lib/chain.js +148 -0
- package/lib/core.js +96 -0
- package/lib/dsl.js +122 -0
- package/lib/error.js +47 -0
- package/lib/event-manager.js +57 -0
- package/lib/finalcb-first-task.js +59 -0
- package/lib/finalcb-task.js +54 -0
- package/lib/fstr.js +110 -0
- package/lib/id.js +10 -0
- package/lib/input-parser.js +44 -0
- package/lib/parse.js +29 -0
- package/lib/pcode.js +164 -0
- package/lib/ret-task.js +67 -0
- package/lib/status.js +5 -0
- package/lib/task.js +234 -0
- package/lib/validate.js +102 -0
- package/lib/vcon.js +76 -0
- package/oldExamples/analyze.js +29 -0
- package/oldExamples/analyze2.js +29 -0
- package/oldExamples/example10-dsl.js +63 -0
- package/oldExamples/example11.js +62 -0
- package/oldExamples/example12.js +63 -0
- package/oldExamples/example13.js +63 -0
- package/oldExamples/example14.js +63 -0
- package/oldExamples/example15.js +75 -0
- package/{test → oldExamples}/example6-ast.js +0 -0
- package/{test → oldExamples}/example6-dsl.js +0 -0
- package/{test → oldExamples}/example8-ast.js +0 -0
- package/{test → oldExamples}/example8-dsl.js +0 -0
- package/{test → oldExamples}/example9-ast.js +0 -0
- package/{test → oldExamples}/example9-dsl.js +0 -0
- package/oldExamples/function-str-ex1.js +33 -0
- package/oldExamples/function-str-ex2.js +67 -0
- package/oldExamples/trait1.js +41 -0
- package/oldExamples/trait2.js +44 -0
- package/package.json +16 -6
- package/react.js +11 -1
- package/test/ast.test.js +69 -0
- package/test/cb-task.test.js +197 -0
- package/test/chain.test.js +239 -0
- package/test/core.test.js +519 -0
- package/test/dsl.test.js +265 -0
- package/test/event-manager.test.js +102 -0
- package/test/exec-options.test.js +32 -0
- package/test/finalcb-task.test.js +37 -0
- package/test/fstr.test.js +288 -0
- package/test/input-parser.test.js +62 -0
- package/test/module-use.test.js +317 -0
- package/test/pcode.test.js +321 -0
- package/test/ret-task.test.js +199 -0
- package/test/task.test.js +21 -0
- package/test/validate-cb-task.test.js +74 -0
- package/test/validate-ret-task.test.js +83 -0
- package/test/validate.test.js +218 -0
- package/test/vcon.test.js +160 -0
- package/lib/react.js +0 -254
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var test = require('tap').test;
|
|
4
|
+
var sprintf = require('sprintf').sprintf;
|
|
5
|
+
|
|
6
|
+
var chainDefine = require('../lib/chain.js');
|
|
7
|
+
|
|
8
|
+
function falpha() { }
|
|
9
|
+
function fbeta() { }
|
|
10
|
+
|
|
11
|
+
test('module exports a function', function (t) {
|
|
12
|
+
t.type(chainDefine, 'function', 'has define by chain method');
|
|
13
|
+
t.type(chainDefine(), 'object', 'has define by chain method');
|
|
14
|
+
t.type(chainDefine().selectFirst, 'function', 'has selectFirst def');
|
|
15
|
+
t.type(chainDefine().in, 'function', 'has input param def');
|
|
16
|
+
t.type(chainDefine().out, 'function', 'has output param def');
|
|
17
|
+
t.type(chainDefine().async, 'function', 'has async - cb type task def');
|
|
18
|
+
t.type(chainDefine().sync, 'function', 'has sync - ret type task def');
|
|
19
|
+
t.type(chainDefine().after, 'function', 'has after prereq def');
|
|
20
|
+
t.type(chainDefine().end, 'function', 'has end to complete flow and validate');
|
|
21
|
+
t.end();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('no arguments -> empty inParams, tasks, outTask', function (t) {
|
|
25
|
+
var fn = chainDefine().end();
|
|
26
|
+
t.deepEqual(fn.ast.inParams, []);
|
|
27
|
+
t.deepEqual(fn.ast.tasks, []);
|
|
28
|
+
t.deepEqual(fn.ast.outTask, { a: [], type: 'finalcb' });
|
|
29
|
+
t.end();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
test('in only -> inParams["foo"], empty tasks, outTask', function (t) {
|
|
34
|
+
var fn = chainDefine()
|
|
35
|
+
.in('foo')
|
|
36
|
+
.end();
|
|
37
|
+
t.deepEqual(fn.ast.inParams, ['foo']);
|
|
38
|
+
t.deepEqual(fn.ast.tasks, []);
|
|
39
|
+
t.deepEqual(fn.ast.outTask, { a: [], type: 'finalcb' });
|
|
40
|
+
t.end();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('in empty -> inParams["foo"], empty tasks, outTask', function (t) {
|
|
44
|
+
var fn = chainDefine()
|
|
45
|
+
.in()
|
|
46
|
+
.end();
|
|
47
|
+
t.deepEqual(fn.ast.inParams, []);
|
|
48
|
+
t.deepEqual(fn.ast.tasks, []);
|
|
49
|
+
t.deepEqual(fn.ast.outTask, { a: [], type: 'finalcb' });
|
|
50
|
+
t.end();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
test('in triple first param -> inParams["foo", "bar", "baz"]', function (t) {
|
|
55
|
+
var fn = chainDefine()
|
|
56
|
+
.in('foo', 'bar', 'baz')
|
|
57
|
+
.end();
|
|
58
|
+
t.deepEqual(fn.ast.inParams, ['foo', 'bar', 'baz']);
|
|
59
|
+
t.deepEqual(fn.ast.tasks, []);
|
|
60
|
+
t.deepEqual(fn.ast.outTask, { a: [], type: 'finalcb' });
|
|
61
|
+
t.end();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('single task, single out params', function (t) {
|
|
65
|
+
var fn = chainDefine()
|
|
66
|
+
.out('c')
|
|
67
|
+
.async(falpha).in('a', 'b').out('c')
|
|
68
|
+
.end();
|
|
69
|
+
t.deepEqual(fn.ast.inParams, []);
|
|
70
|
+
t.deepEqual(fn.ast.tasks, [
|
|
71
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'falpha' }
|
|
72
|
+
]);
|
|
73
|
+
t.deepEqual(fn.ast.outTask, { a: ['c'], type: 'finalcb' });
|
|
74
|
+
t.end();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('single task, err and out params', function (t) {
|
|
78
|
+
var fn = chainDefine()
|
|
79
|
+
.out('err', 'c')
|
|
80
|
+
.async(falpha).in('a', 'b').out('err', 'c')
|
|
81
|
+
.end();
|
|
82
|
+
t.deepEqual(fn.ast.inParams, []);
|
|
83
|
+
t.deepEqual(fn.ast.tasks, [
|
|
84
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'falpha' }
|
|
85
|
+
]);
|
|
86
|
+
t.deepEqual(fn.ast.outTask, { a: ['c'], type: 'finalcb' });
|
|
87
|
+
t.end();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('single task, ERR and out params', function (t) {
|
|
91
|
+
var fn = chainDefine()
|
|
92
|
+
.out('ERR', 'c')
|
|
93
|
+
.async(falpha).in('a', 'b').out('ERR', 'c')
|
|
94
|
+
.end();
|
|
95
|
+
t.deepEqual(fn.ast.inParams, []);
|
|
96
|
+
t.deepEqual(fn.ast.tasks, [
|
|
97
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'falpha' }
|
|
98
|
+
]);
|
|
99
|
+
t.deepEqual(fn.ast.outTask, { a: ['c'], type: 'finalcb' });
|
|
100
|
+
t.end();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('cb used in defs is simply ignored', function (t) {
|
|
104
|
+
var fn = chainDefine()
|
|
105
|
+
.in('a', 'b', 'cb')
|
|
106
|
+
.out('err', 'c')
|
|
107
|
+
.async(falpha).in('a', 'b', 'cb').out('err', 'c')
|
|
108
|
+
.end();
|
|
109
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
110
|
+
t.deepEqual(fn.ast.tasks, [
|
|
111
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'falpha'}
|
|
112
|
+
]);
|
|
113
|
+
t.deepEqual(fn.ast.outTask, { a: ['c'], type: 'finalcb' });
|
|
114
|
+
t.end();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('callback used in defs is simply ignored', function (t) {
|
|
118
|
+
var fn = chainDefine()
|
|
119
|
+
.in('a', 'b', 'callback')
|
|
120
|
+
.out('err', 'c')
|
|
121
|
+
.async(falpha).in('a', 'b', 'callback').out('err', 'c')
|
|
122
|
+
.end();
|
|
123
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
124
|
+
t.deepEqual(fn.ast.tasks, [
|
|
125
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'falpha'}
|
|
126
|
+
]);
|
|
127
|
+
t.deepEqual(fn.ast.outTask, { a: ['c'], type: 'finalcb' });
|
|
128
|
+
t.end();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('two inputs, two tasks, two out params', function (t) {
|
|
132
|
+
var fn = chainDefine()
|
|
133
|
+
.in('a', 'b', 'cb')
|
|
134
|
+
.out('err', 'c', 'd')
|
|
135
|
+
.async(falpha).in('a', 'b', 'cb').out('err', 'c')
|
|
136
|
+
.async(fbeta).in('a', 'b', 'cb').out('err', 'd', 'e')
|
|
137
|
+
.end();
|
|
138
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
139
|
+
t.deepEqual(fn.ast.tasks, [
|
|
140
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'falpha'},
|
|
141
|
+
{ f: fbeta, type: 'cb', a: ['a', 'b'], out: ['d', 'e'], name: 'fbeta'}
|
|
142
|
+
]);
|
|
143
|
+
t.deepEqual(fn.ast.outTask, { a: ['c', 'd'], type: 'finalcb' });
|
|
144
|
+
t.end();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('two inputs, two tasks, two out params, name, options', function (t) {
|
|
148
|
+
var fn = chainDefine()
|
|
149
|
+
.name('myflow')
|
|
150
|
+
.in('a', 'b', 'cb')
|
|
151
|
+
.out('err', 'c', 'd')
|
|
152
|
+
.options({ otherOptFoo: 'foo'})
|
|
153
|
+
.async(falpha).in('a', 'b', 'cb').out('err', 'c').name('myalpha')
|
|
154
|
+
.async(fbeta).in('a', 'b', 'cb').out('err', 'd', 'e').options({ bar: 'bar'})
|
|
155
|
+
.end();
|
|
156
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
157
|
+
t.deepEqual(fn.ast.tasks, [
|
|
158
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'myalpha'},
|
|
159
|
+
{ f: fbeta, type: 'cb', a: ['a', 'b'], out: ['d', 'e'],
|
|
160
|
+
bar: 'bar', name: 'fbeta' }
|
|
161
|
+
]);
|
|
162
|
+
t.deepEqual(fn.ast.outTask, { a: ['c', 'd'], type: 'finalcb' });
|
|
163
|
+
t.equal(fn.ast.name, 'myflow', 'name should match if supplied');
|
|
164
|
+
t.equal(fn.ast.otherOptFoo, 'foo', 'other options should pass through');
|
|
165
|
+
t.end();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('two inputs, two mixed tasks, two out params', function (t) {
|
|
169
|
+
var fn = chainDefine()
|
|
170
|
+
.in('a', 'b', 'cb')
|
|
171
|
+
.out('err', 'c', 'd')
|
|
172
|
+
.async(falpha).in('a', 'b', 'cb').out('err', 'c')
|
|
173
|
+
.sync(fbeta).in('a', 'b').out('d')
|
|
174
|
+
.end();
|
|
175
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
176
|
+
t.deepEqual(fn.ast.tasks, [
|
|
177
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'falpha'},
|
|
178
|
+
{ f: fbeta, type: 'ret', a: ['a', 'b'], out: ['d'], name: 'fbeta'}
|
|
179
|
+
]);
|
|
180
|
+
t.deepEqual(fn.ast.outTask, { a: ['c', 'd'], type: 'finalcb' });
|
|
181
|
+
t.end();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('two inputs, two mixed tasks, two out params, opts', function (t) {
|
|
185
|
+
var fn = chainDefine()
|
|
186
|
+
.in('a', 'b', 'cb')
|
|
187
|
+
.out('err', 'c', 'd')
|
|
188
|
+
.async(falpha).in('a', 'b', 'cb').out('err', 'c').after(fbeta)
|
|
189
|
+
.sync(fbeta).in('a', 'b').out('d')
|
|
190
|
+
.end();
|
|
191
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
192
|
+
t.deepEqual(fn.ast.tasks, [
|
|
193
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], after: ['fbeta'], name: 'falpha'},
|
|
194
|
+
{ f: fbeta, type: 'ret', a: ['a', 'b'], out: ['d'], name: 'fbeta'}
|
|
195
|
+
]);
|
|
196
|
+
t.deepEqual(fn.ast.outTask, { a: ['c', 'd'], type: 'finalcb' });
|
|
197
|
+
t.end();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Object use
|
|
201
|
+
test('object prop task params', function (t) {
|
|
202
|
+
var fn = chainDefine()
|
|
203
|
+
.in('a', 'b', 'cb')
|
|
204
|
+
.out('err', 'c', 'e')
|
|
205
|
+
.async(falpha).in('a', 'b.cat', 'cb').out('err', 'c')
|
|
206
|
+
.sync(fbeta).in('c.dog', 'b').out('d')
|
|
207
|
+
.async('d.egg').in('c').out('err', 'e')
|
|
208
|
+
.end();
|
|
209
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
210
|
+
t.deepEqual(fn.ast.tasks, [
|
|
211
|
+
{ f: falpha, type: 'cb', a: ['a', 'b.cat'], out: ['c'], name: 'falpha'},
|
|
212
|
+
{ f: fbeta, type: 'ret', a: ['c.dog', 'b'], out: ['d'], name: 'fbeta'},
|
|
213
|
+
{ f: 'd.egg', type: 'cb', a: ['c'], out: ['e'], name: 'd.egg'}
|
|
214
|
+
]);
|
|
215
|
+
t.deepEqual(fn.ast.outTask, { a: ['c', 'e'], type: 'finalcb' });
|
|
216
|
+
t.end();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
// selectFirst
|
|
221
|
+
|
|
222
|
+
test('selectFirst', function (t) {
|
|
223
|
+
var fn = chainDefine()
|
|
224
|
+
.selectFirst()
|
|
225
|
+
.in('a', 'b', 'cb')
|
|
226
|
+
.out('err', 'c')
|
|
227
|
+
.async(falpha).in('a', 'b', 'cb').out('err', 'c')
|
|
228
|
+
.sync(fbeta).in('a', 'b').out('c')
|
|
229
|
+
.end();
|
|
230
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
231
|
+
t.deepEqual(fn.ast.tasks, [
|
|
232
|
+
{ f: falpha, type: 'cb', a: ['a', 'b'], out: ['c'], name: 'falpha'},
|
|
233
|
+
{ f: fbeta, type: 'ret', a: ['a', 'b'], out: ['c'], name: 'fbeta', after: ['falpha']}
|
|
234
|
+
]);
|
|
235
|
+
t.deepEqual(fn.ast.outTask, { a: ['c'], type: 'finalcbFirst' });
|
|
236
|
+
t.end();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var test = require('tap').test;
|
|
4
|
+
|
|
5
|
+
var react = require('../react');
|
|
6
|
+
|
|
7
|
+
function multiply(x, y, cb) { cb(null, x * y); }
|
|
8
|
+
function add(x, y, cb) { cb(null, x + y); }
|
|
9
|
+
function badFunc(a, b, cb) { throw new Error('badFuncThrow'); }
|
|
10
|
+
function badF2(a, b, cb) { cb('my-error'); }
|
|
11
|
+
function fnRetsSum(a, b) { return a + b; }
|
|
12
|
+
|
|
13
|
+
test('set and validate AST', function (t) {
|
|
14
|
+
var fn = react();
|
|
15
|
+
var errors = fn.setAndValidateAST({
|
|
16
|
+
name: 'myflow',
|
|
17
|
+
inParams: ['a', 'b'],
|
|
18
|
+
tasks: [
|
|
19
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'] }
|
|
20
|
+
],
|
|
21
|
+
outTask: { a: ['c'] },
|
|
22
|
+
otherOpt: 'foo',
|
|
23
|
+
otherOpt2: 'bar'
|
|
24
|
+
});
|
|
25
|
+
t.deepEqual(errors, [], 'should set and validate as true');
|
|
26
|
+
t.deepEqual(fn.ast.inParams, ['a', 'b']);
|
|
27
|
+
t.deepEqual(fn.ast.tasks, [
|
|
28
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'], type: 'cb', name: 'multiply' }
|
|
29
|
+
]);
|
|
30
|
+
t.deepEqual(fn.ast.outTask, { a: ['c'], type: 'finalcb' });
|
|
31
|
+
t.equal(fn.ast.name, 'myflow', 'name should match if set');
|
|
32
|
+
t.equal(fn.ast.otherOpt, 'foo', 'any additional options should pass through');
|
|
33
|
+
t.end();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('unnamed tasks will be assigned unique names', function (t) {
|
|
37
|
+
var fn = react();
|
|
38
|
+
var errors = fn.setAndValidateAST({
|
|
39
|
+
inParams: ['a', 'b'],
|
|
40
|
+
tasks: [
|
|
41
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'] },
|
|
42
|
+
{ f: multiply, a: ['a', 'b'], out: ['d'], name: 'multiply' },
|
|
43
|
+
{ f: multiply, a: ['a', 'b'], out: ['e'], name: 'times' },
|
|
44
|
+
{ f: multiply, a: ['a', 'b'], out: ['f'] }
|
|
45
|
+
],
|
|
46
|
+
outTask: { a: ['c'] }
|
|
47
|
+
});
|
|
48
|
+
t.deepEqual(errors, [], 'should set and validate as true');
|
|
49
|
+
t.deepEqual(fn.ast.tasks, [
|
|
50
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'], type: 'cb', name: 'multiply_0' },
|
|
51
|
+
{ f: multiply, a: ['a', 'b'], out: ['d'], name: 'multiply', type: 'cb' },
|
|
52
|
+
{ f: multiply, a: ['a', 'b'], out: ['e'], name: 'times', type: 'cb' },
|
|
53
|
+
{ f: multiply, a: ['a', 'b'], out: ['f'], type: 'cb', name: 'multiply_3' }
|
|
54
|
+
]);
|
|
55
|
+
t.end();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
test('execution with no errors should call callback with result', function (t) {
|
|
60
|
+
var fn = react();
|
|
61
|
+
var errors = fn.setAndValidateAST({
|
|
62
|
+
inParams: ['a', 'b'],
|
|
63
|
+
tasks: [
|
|
64
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'] }
|
|
65
|
+
],
|
|
66
|
+
outTask: { a: ['c'] }
|
|
67
|
+
});
|
|
68
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
69
|
+
fn(2, 3, function (err, c) {
|
|
70
|
+
t.equal(err, null);
|
|
71
|
+
t.equal(c, 6);
|
|
72
|
+
t.end();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('multi-step', function (t) {
|
|
77
|
+
t.plan(4);
|
|
78
|
+
var fn = react();
|
|
79
|
+
var errors = fn.setAndValidateAST({
|
|
80
|
+
inParams: ['a', 'b'],
|
|
81
|
+
tasks: [
|
|
82
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'] },
|
|
83
|
+
{ f: add, a: ['c', 'b'], out: ['d'] }
|
|
84
|
+
],
|
|
85
|
+
outTask: { a: ['c', 'd'] }
|
|
86
|
+
});
|
|
87
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
88
|
+
|
|
89
|
+
fn(2, 3, function (err, c, d) {
|
|
90
|
+
t.equal(err, null);
|
|
91
|
+
t.equal(c, 6);
|
|
92
|
+
t.equal(d, 9);
|
|
93
|
+
t.end();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('multi-step with after as nonarr fn', function (t) {
|
|
98
|
+
t.plan(7);
|
|
99
|
+
var fn = react();
|
|
100
|
+
var errors = fn.setAndValidateAST({
|
|
101
|
+
inParams: ['a', 'b'],
|
|
102
|
+
tasks: [
|
|
103
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'], after: add },
|
|
104
|
+
{ f: add, a: ['a', 'b'], out: ['d'] }
|
|
105
|
+
],
|
|
106
|
+
outTask: { a: ['c', 'd'] }
|
|
107
|
+
});
|
|
108
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
109
|
+
|
|
110
|
+
var events = [];
|
|
111
|
+
function accumEvents(task) {
|
|
112
|
+
events.push(task);
|
|
113
|
+
}
|
|
114
|
+
fn.events.on('task.complete', accumEvents);
|
|
115
|
+
|
|
116
|
+
fn(2, 3, function (err, c, d) {
|
|
117
|
+
t.equal(err, null);
|
|
118
|
+
t.equal(c, 6);
|
|
119
|
+
t.equal(d, 5);
|
|
120
|
+
t.equal(events.length, 2, 'should have seen one task compl events');
|
|
121
|
+
t.equal(events[0].name, 'add', 'name matches');
|
|
122
|
+
t.equal(events[1].name, 'multiply', 'name matches');
|
|
123
|
+
t.end();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('mixed multi-step with after as nonarr fn w/events', function (t) {
|
|
128
|
+
t.plan(19);
|
|
129
|
+
var fn = react();
|
|
130
|
+
var errors = fn.setAndValidateAST({
|
|
131
|
+
inParams: ['a', 'b'],
|
|
132
|
+
tasks: [
|
|
133
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'], after: fnRetsSum },
|
|
134
|
+
{ f: fnRetsSum, a: ['a', 'b'], out: ['d'], type: 'ret' }
|
|
135
|
+
],
|
|
136
|
+
outTask: { a: ['c', 'd'] }
|
|
137
|
+
});
|
|
138
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
139
|
+
|
|
140
|
+
var events = [];
|
|
141
|
+
function accumEvents(task) {
|
|
142
|
+
events.push(task);
|
|
143
|
+
}
|
|
144
|
+
fn.events.on('task.complete', accumEvents);
|
|
145
|
+
|
|
146
|
+
fn(2, 3, function (err, c, d) {
|
|
147
|
+
t.equal(err, null);
|
|
148
|
+
t.equal(c, 6);
|
|
149
|
+
t.equal(d, 5);
|
|
150
|
+
t.equal(events.length, 2, 'should have seen one task compl events');
|
|
151
|
+
t.equal(events[0].name, 'fnRetsSum', 'name matches');
|
|
152
|
+
t.ok(events[0].id, 'has unique id');
|
|
153
|
+
t.ok(events[0].startTime, 'has startTime');
|
|
154
|
+
t.ok(events[0].endTime, 'has endTime');
|
|
155
|
+
t.ok(events[0].elapsedTime !== undefined, 'has elapsedTime');
|
|
156
|
+
t.ok(events[0].args, 'has args');
|
|
157
|
+
t.ok(events[0].results, 'has results');
|
|
158
|
+
t.equal(events[1].name, 'multiply', 'name matches');
|
|
159
|
+
t.ok(events[1].id, 'has unique id');
|
|
160
|
+
t.ok(events[1].startTime, 'has startTime');
|
|
161
|
+
t.ok(events[1].endTime, 'has endTime');
|
|
162
|
+
t.ok(events[1].elapsedTime !== undefined, 'has elapsedTime');
|
|
163
|
+
t.ok(events[1].args, 'has args');
|
|
164
|
+
t.ok(events[1].results, 'has results');
|
|
165
|
+
t.end();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
test('sets obj values', function (t) {
|
|
173
|
+
t.plan(5);
|
|
174
|
+
var fn = react();
|
|
175
|
+
var errors = fn.setAndValidateAST({
|
|
176
|
+
inParams: ['a', 'b', 'c'],
|
|
177
|
+
tasks: [
|
|
178
|
+
{ f: multiply, a: ['a', 'b'], out: ['c.mult'] },
|
|
179
|
+
{ f: fnRetsSum, a: ['c.mult', 'b'], out: ['c.sum'], type: 'ret' }
|
|
180
|
+
],
|
|
181
|
+
outTask: { a: ['c.mult', 'c.sum', 'c'] }
|
|
182
|
+
});
|
|
183
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
184
|
+
|
|
185
|
+
fn(2, 3, { foo: 1 }, function (err, cmult, csum, c) {
|
|
186
|
+
t.deepEqual(err, null, 'should be no err');
|
|
187
|
+
t.equal(cmult, 6);
|
|
188
|
+
t.equal(csum, 9);
|
|
189
|
+
t.deepEqual(c, { foo: 1, mult: 6, sum: 9});
|
|
190
|
+
t.end();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('error when cant complete', function (t) {
|
|
195
|
+
t.plan(2);
|
|
196
|
+
var fn = react();
|
|
197
|
+
var errors = fn.setAndValidateAST({
|
|
198
|
+
inParams: ['a', 'b', 'c'],
|
|
199
|
+
tasks: [
|
|
200
|
+
{ f: multiply, a: ['a', 'b'], out: ['c.mult'] },
|
|
201
|
+
{ f: fnRetsSum, a: ['c.bad', 'b'], out: ['c.sum'], type: 'ret' }
|
|
202
|
+
],
|
|
203
|
+
outTask: { a: ['c.mult', 'c.sum', 'c'] }
|
|
204
|
+
});
|
|
205
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
206
|
+
|
|
207
|
+
fn(2, 3, { foo: 1 }, function (err, cmult, csum, c) {
|
|
208
|
+
t.equal(err.message, 'no tasks running, flow will not complete');
|
|
209
|
+
t.end();
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
test('objects', function (t) {
|
|
215
|
+
function retObj(a, b, cb) { cb(null, { bar: a + b }); }
|
|
216
|
+
function concat(a, b, cb) { cb(null, { result: a + b }); }
|
|
217
|
+
t.plan(4);
|
|
218
|
+
var fn = react();
|
|
219
|
+
var errors = fn.setAndValidateAST({
|
|
220
|
+
inParams: ['a', 'b'],
|
|
221
|
+
tasks: [
|
|
222
|
+
{ f: retObj, a: ['a.foo', 'b'], out: ['c'] },
|
|
223
|
+
{ f: concat, a: ['c.bar', 'b'], out: ['d'] }
|
|
224
|
+
],
|
|
225
|
+
outTask: { a: ['c', 'd.result'] }
|
|
226
|
+
});
|
|
227
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
228
|
+
|
|
229
|
+
fn({ foo: 'FOO' }, 'B', function (err, c, dresult) {
|
|
230
|
+
t.equal(err, null);
|
|
231
|
+
t.deepEqual(c, { bar: 'FOOB' });
|
|
232
|
+
t.equal(dresult, 'FOOBB');
|
|
233
|
+
t.end();
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('objects from container', function (t) {
|
|
238
|
+
var C = {
|
|
239
|
+
retObj: function retObj(a, b, cb) { cb(null, { bar: a + b }); },
|
|
240
|
+
concat: function concat(a, b, cb) { cb(null, { result: a + b }); }
|
|
241
|
+
};
|
|
242
|
+
t.plan(4);
|
|
243
|
+
var fn = react();
|
|
244
|
+
var errors = fn.setAndValidateAST({
|
|
245
|
+
inParams: ['a', 'b'],
|
|
246
|
+
tasks: [
|
|
247
|
+
{ f: C.retObj, a: ['a.foo', 'b'], out: ['c'] },
|
|
248
|
+
{ f: C.concat, a: ['c.bar', 'b'], out: ['d'] }
|
|
249
|
+
],
|
|
250
|
+
outTask: { a: ['c', 'd.result'] }
|
|
251
|
+
});
|
|
252
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
253
|
+
|
|
254
|
+
fn({ foo: 'FOO' }, 'B', function (err, c, dresult) {
|
|
255
|
+
t.equal(err, null);
|
|
256
|
+
t.deepEqual(c, { bar: 'FOOB' });
|
|
257
|
+
t.equal(dresult, 'FOOBB');
|
|
258
|
+
t.end();
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('objects from container input arg', function (t) {
|
|
263
|
+
var CONT = {
|
|
264
|
+
retObj: function retObj(a, b, cb) { cb(null, { bar: a + b }); },
|
|
265
|
+
concat: function concat(a, b, cb) { cb(null, { result: a + b }); }
|
|
266
|
+
};
|
|
267
|
+
t.plan(4);
|
|
268
|
+
var fn = react();
|
|
269
|
+
var errors = fn.setAndValidateAST({
|
|
270
|
+
inParams: ['a', 'b', 'CONT'],
|
|
271
|
+
tasks: [
|
|
272
|
+
{ f: 'CONT.retObj', a: ['a.foo', 'b'], out: ['c'] },
|
|
273
|
+
{ f: 'CONT.concat', a: ['c.bar', 'b'], out: ['d'] }
|
|
274
|
+
],
|
|
275
|
+
outTask: { a: ['c', 'd.result'] }
|
|
276
|
+
});
|
|
277
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
fn({ foo: 'FOO' }, 'B', CONT, function (err, c, dresult) {
|
|
281
|
+
t.equal(err, null);
|
|
282
|
+
t.deepEqual(c, { bar: 'FOOB' });
|
|
283
|
+
t.equal(dresult, 'FOOBB');
|
|
284
|
+
t.end();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('use locals for functions', function (t) {
|
|
289
|
+
var locals = {
|
|
290
|
+
retObj: function retObj(a, b, cb) { cb(null, { bar: a + b }); },
|
|
291
|
+
concat: function concat(a, b, cb) { cb(null, { result: a + b }); }
|
|
292
|
+
};
|
|
293
|
+
t.plan(4);
|
|
294
|
+
var fn = react();
|
|
295
|
+
var errors = fn.setAndValidateAST({
|
|
296
|
+
inParams: ['a', 'b'],
|
|
297
|
+
tasks: [
|
|
298
|
+
{ f: 'retObj', a: ['a.foo', 'b'], out: ['c'] },
|
|
299
|
+
{ f: 'concat', a: ['c.bar', 'b'], out: ['d'] }
|
|
300
|
+
],
|
|
301
|
+
outTask: { a: ['c', 'd.result'] },
|
|
302
|
+
locals: locals
|
|
303
|
+
});
|
|
304
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
305
|
+
|
|
306
|
+
fn({ foo: 'FOO' }, 'B', function (err, c, dresult) {
|
|
307
|
+
t.equal(err, null);
|
|
308
|
+
t.deepEqual(c, { bar: 'FOOB' });
|
|
309
|
+
t.equal(dresult, 'FOOBB');
|
|
310
|
+
t.end();
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test('objects from locals', function (t) {
|
|
315
|
+
var CONT = {
|
|
316
|
+
retObj: function retObj(a, b, cb) { cb(null, { bar: a + b }); },
|
|
317
|
+
concat: function concat(a, b, cb) { cb(null, { result: a + b }); }
|
|
318
|
+
};
|
|
319
|
+
t.plan(4);
|
|
320
|
+
var fn = react();
|
|
321
|
+
var errors = fn.setAndValidateAST({
|
|
322
|
+
inParams: ['a', 'b'],
|
|
323
|
+
tasks: [
|
|
324
|
+
{ f: 'CONT.retObj', a: ['a.foo', 'b'], out: ['c'] },
|
|
325
|
+
{ f: 'CONT.concat', a: ['c.bar', 'b'], out: ['d'] }
|
|
326
|
+
],
|
|
327
|
+
outTask: { a: ['c', 'd.result'] },
|
|
328
|
+
locals: { CONT: CONT }
|
|
329
|
+
});
|
|
330
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
fn({ foo: 'FOO' }, 'B', function (err, c, dresult) {
|
|
334
|
+
t.equal(err, null);
|
|
335
|
+
t.deepEqual(c, { bar: 'FOOB' });
|
|
336
|
+
t.equal(dresult, 'FOOBB');
|
|
337
|
+
t.end();
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test('multi-step func throws, cb with error', function (t) {
|
|
342
|
+
t.plan(2);
|
|
343
|
+
var fn = react();
|
|
344
|
+
var errors = fn.setAndValidateAST({
|
|
345
|
+
inParams: ['a', 'b'],
|
|
346
|
+
tasks: [
|
|
347
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'] },
|
|
348
|
+
{ f: badFunc, a: ['c', 'b'], out: ['d'] }
|
|
349
|
+
],
|
|
350
|
+
outTask: { a: ['c', 'd'] }
|
|
351
|
+
});
|
|
352
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
353
|
+
|
|
354
|
+
fn(2, 3, function (err, c, d) {
|
|
355
|
+
t.equal(err.message, 'badFuncThrow');
|
|
356
|
+
t.end();
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('multi-step func cb err, cb with error', function (t) {
|
|
361
|
+
t.plan(2);
|
|
362
|
+
var fn = react();
|
|
363
|
+
var errors = fn.setAndValidateAST({
|
|
364
|
+
inParams: ['a', 'b'],
|
|
365
|
+
tasks: [
|
|
366
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'] },
|
|
367
|
+
{ f: badF2, a: ['c', 'b'], out: ['d'] },
|
|
368
|
+
{ f: add, a: ['d', 'b'], out: ['e'] }
|
|
369
|
+
],
|
|
370
|
+
outTask: { a: ['c', 'e'] }
|
|
371
|
+
});
|
|
372
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
373
|
+
|
|
374
|
+
fn(2, 3, function (err, c, d) {
|
|
375
|
+
t.equal(err.message, 'my-error');
|
|
376
|
+
t.end();
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
test('selectFirst with first succeeding', function (t) {
|
|
382
|
+
t.plan(6);
|
|
383
|
+
var fn = react();
|
|
384
|
+
var errors = fn.setAndValidateAST({
|
|
385
|
+
inParams: ['a', 'b'],
|
|
386
|
+
tasks: [
|
|
387
|
+
{ f: multiply, a: ['a', 'b'], out: ['c'] },
|
|
388
|
+
{ f: add, a: ['a', 'b'], out: ['c'], after: ['multiply'] }
|
|
389
|
+
],
|
|
390
|
+
outTask: { type: 'finalcbFirst', a: ['c'] }
|
|
391
|
+
});
|
|
392
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
393
|
+
|
|
394
|
+
var events = [];
|
|
395
|
+
function accumEvents(task) {
|
|
396
|
+
events.push(task);
|
|
397
|
+
}
|
|
398
|
+
fn.events.on('task.complete', accumEvents);
|
|
399
|
+
|
|
400
|
+
fn(2, 3, function (err, c, d) {
|
|
401
|
+
t.equal(err, null);
|
|
402
|
+
t.equal(c, 6);
|
|
403
|
+
t.equal(events.length, 1, 'should have seen one task compl events');
|
|
404
|
+
t.equal(events[0].name, 'multiply', 'name matches');
|
|
405
|
+
t.deepEqual(events[0].results, [6], 'results match');
|
|
406
|
+
t.end();
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test('selectFirst with third succeeding', function (t) {
|
|
411
|
+
function noSuccess(a, b, cb) { cb(null); } // returns undefined result
|
|
412
|
+
function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
|
|
413
|
+
|
|
414
|
+
t.plan(6);
|
|
415
|
+
var fn = react();
|
|
416
|
+
var errors = fn.setAndValidateAST({
|
|
417
|
+
inParams: ['a', 'b'],
|
|
418
|
+
tasks: [
|
|
419
|
+
{ f: noSuccess, a: ['a', 'b'], out: ['c'] },
|
|
420
|
+
{ f: noSuccessNull, a: ['a', 'b'], out: ['c'], after: ['noSuccess'] },
|
|
421
|
+
{ f: add, a: ['a', 'b'], out: ['c'], after: ['noSuccessNull'] }
|
|
422
|
+
],
|
|
423
|
+
outTask: { type: 'finalcbFirst', a: ['c'] }
|
|
424
|
+
});
|
|
425
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
426
|
+
|
|
427
|
+
var events = [];
|
|
428
|
+
function accumEvents(task) {
|
|
429
|
+
events.push(task);
|
|
430
|
+
}
|
|
431
|
+
fn.events.on('task.complete', accumEvents);
|
|
432
|
+
|
|
433
|
+
fn(2, 3, function (err, c, d) {
|
|
434
|
+
t.equal(err, null);
|
|
435
|
+
t.equal(c, 5);
|
|
436
|
+
t.equal(events.length, 3, 'should have seen three task compl events');
|
|
437
|
+
t.equal(events[2].name, 'add', 'name matches');
|
|
438
|
+
t.deepEqual(events[2].results, [5], 'results match');
|
|
439
|
+
t.end();
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
test('selectFirst forces order with third succeeding', function (t) {
|
|
445
|
+
function noSuccess(a, b, cb) {
|
|
446
|
+
setTimeout(function () { cb(null); }, 100); // returns undefined result
|
|
447
|
+
}
|
|
448
|
+
function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
|
|
449
|
+
|
|
450
|
+
t.plan(8);
|
|
451
|
+
var fn = react();
|
|
452
|
+
var errors = fn.setAndValidateAST({
|
|
453
|
+
inParams: ['a', 'b'],
|
|
454
|
+
tasks: [
|
|
455
|
+
{ f: noSuccess, a: ['a', 'b'], out: ['c'] },
|
|
456
|
+
{ f: noSuccessNull, a: ['a', 'b'], out: ['c'], after: ['noSuccess']},
|
|
457
|
+
{ f: add, a: ['a', 'b'], out: ['c'], after: ['noSuccessNull'] },
|
|
458
|
+
{ f: noSuccess, a: ['a', 'b'], out: ['c'], after: ['add'] }
|
|
459
|
+
],
|
|
460
|
+
outTask: { type: 'finalcbFirst', a: ['c'] }
|
|
461
|
+
});
|
|
462
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
463
|
+
|
|
464
|
+
var events = [];
|
|
465
|
+
function accumEvents(task) {
|
|
466
|
+
events.push(task);
|
|
467
|
+
}
|
|
468
|
+
fn.events.on('task.complete', accumEvents);
|
|
469
|
+
|
|
470
|
+
fn(2, 3, function (err, c, d) {
|
|
471
|
+
t.equal(err, null);
|
|
472
|
+
t.equal(c, 5);
|
|
473
|
+
t.equal(events.length, 3, 'should have seen three task compl events');
|
|
474
|
+
t.equal(events[0].name, 'noSuccess', 'name matches');
|
|
475
|
+
t.equal(events[1].name, 'noSuccessNull', 'name matches');
|
|
476
|
+
t.equal(events[2].name, 'add', 'name matches');
|
|
477
|
+
t.deepEqual(events[2].results, [5], 'results match');
|
|
478
|
+
t.end();
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
test('selectFirst using direct returns', function (t) {
|
|
486
|
+
function noSuccess(a, b) { } // returns undefined result
|
|
487
|
+
function noSuccessNull(a, b) { return null; } // returns null result
|
|
488
|
+
function addRet(a, b) { return a + b; }
|
|
489
|
+
|
|
490
|
+
t.plan(6);
|
|
491
|
+
var fn = react();
|
|
492
|
+
var errors = fn.setAndValidateAST({
|
|
493
|
+
inParams: ['a', 'b'],
|
|
494
|
+
tasks: [
|
|
495
|
+
{ f: noSuccess, a: ['a', 'b'], out: ['c'], type: 'ret' },
|
|
496
|
+
{ f: noSuccessNull, a: ['a', 'b'], out: ['c'], type: 'ret', after: ['noSuccess'] },
|
|
497
|
+
{ f: addRet, a: ['a', 'b'], out: ['c'], type: 'ret', after: ['noSuccessNull'] }
|
|
498
|
+
],
|
|
499
|
+
outTask: { type: 'finalcbFirst', a: ['c'] }
|
|
500
|
+
});
|
|
501
|
+
t.deepEqual(errors, [], 'no validation errors');
|
|
502
|
+
|
|
503
|
+
var events = [];
|
|
504
|
+
function accumEvents(task) {
|
|
505
|
+
events.push(task);
|
|
506
|
+
}
|
|
507
|
+
fn.events.on('task.complete', accumEvents);
|
|
508
|
+
|
|
509
|
+
fn(2, 3, function (err, c, d) {
|
|
510
|
+
t.equal(err, null);
|
|
511
|
+
t.equal(c, 5);
|
|
512
|
+
t.equal(events.length, 3, 'should have seen three task compl events');
|
|
513
|
+
t.equal(events[2].name, 'addRet', 'name matches');
|
|
514
|
+
t.deepEqual(events[2].results, [5], 'results match');
|
|
515
|
+
t.end();
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
|