/
ctrlflow.v1-api.asynct.js
120 lines (93 loc) · 1.96 KB
/
ctrlflow.v1-api.asynct.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var ctrl = require('../ctrlflow')
, it = require('it-is')
exports ['seq returns a function'] = function (test){
var go = ctrl.seq([
function (){ this.next() }])
it(go).isFunction ()
test.done()
}
exports ['pass callback to seq function'] = function (test){
var go = ctrl.seq([
function (){
this.next()
}])
go(test.done)
}
exports ['pass error to callback of seq function'] = function (test){
var err = new Error('example error')
var go = ctrl.seq([
function (){
throw err
}])
go(function (_err) {
it(_err).equal(err)
test.done()
})
}
exports ['pass [function, arg1, arg2, arg3,...] to set args'] = function (test) {
var args = [1,0,2,2,4], called = 0
var go = ctrl.seq([
[function (){
var _args = [].slice.call(arguments)
called ++
var cb = _args.pop()
it(cb).isFunction ()
it(args).deepEqual(_args)
cb()
},1,0,2,2,4],
[function (cb) {cb()}]
])
go(function (err) {
if (err) throw err
it(called).equal(1)
test.done()
})
}
exports ['call many [function, arg1, arg2, arg3,...] style steps'] = function (test) {
var called = 0
, funx = function (){
called ++
var cb = [].pop.call(arguments)
it(cb).isFunction ()
cb()
}
var go = ctrl.seq([
[funx],
[funx],
[funx],
[funx],
[funx]
])
go(function (err) {
if (err) throw err
it(called).equal(5)
test.done()
})
}
exports ['ignore null step'] = function (test) {
var called = 0
, funx = function () {
called ++
var cb = [].pop.call(arguments)
it(cb).isFunction ()
cb()
}
var go = ctrl.seq([
[funx],
null,
null,
[funx]
])
go(function (err) {
if (err) throw err
it(called).equal(2)
test.done()
})
}
exports ['exports seq directly'] = function (test) {
//
// check that ctrlflow is usable directly from the require('ctrlflow')
//
it(ctrl).equal(ctrl.seq)
test.done()
}