test.js
1.45 KB
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
var assert = require('assert')
var series = require('./')
var a, b, c
series([
function (done) {
a = 1
process.nextTick(done)
check('a')
},
function (done) {
b = 2
process.nextTick(done)
check('b')
},
function (done) {
c = 3
process.nextTick(done)
check('c')
}
], function (err) {
assert.ifError(err)
assert.equal(a, 1)
assert.equal(b, 2)
assert.equal(c, 3)
})
function check(x) {
switch (x) {
case 'a':
assert.equal(a, 1)
assert.equal(b, undefined)
assert.equal(c, undefined)
break
case 'b':
assert.equal(a, 1)
assert.equal(b, 2)
assert.equal(c, undefined)
break
case 'c':
assert.equal(a, 1)
assert.equal(b, 2)
assert.equal(c, 3)
break
}
}
var context = 'hello'
series([function (done) {
assert.equal(this, context)
done()
}], context)
var finished
series([], function (err) {
finished = true
})
process.nextTick(function () {
if (!finished)
throw new Error('Failed with no functions.');
})
var r, d, o
series([
function (done) {
r = 1
process.nextTick(done)
},
function (done) {
d = 0
process.nextTick(function () {
done(new Error('message'))
})
},
function (done) {
o = 0
process.nextTick(done)
}
], function (err) {
assert.equal(err.message, 'message')
assert.equal(r, 1)
assert.equal(d, 0)
assert.equal(o, undefined)
})
console.log('Array series tests pass!')