-
Notifications
You must be signed in to change notification settings - Fork 64
/
results.js
65 lines (55 loc) · 1.07 KB
/
results.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
import tap from 'tap-esm';
import Queue from '../index.js'
tap('results', (t) => {
t.plan(5)
const q = new Queue({ results: [] })
q.push(
(cb) => cb(undefined, 42),
(cb) => cb(undefined, 3, 2, 1),
(cb) => cb()
)
q.unshift((cb) => {
setTimeout(() => {
cb(undefined, 'string')
}, 10)
})
q.start((err, results) => {
t.notOk(err);
[
['string'],
[42],
[3, 2, 1],
[]
].forEach((expected, i) => {
t.arrayEqual(expected, results[i])
})
})
})
tap('results from start(). start() should return a promise with error data and results', async (t) => {
t.plan(5)
const q = new Queue({ results: [] })
q.push(
(cb) => cb(undefined, 42),
(cb) => cb(undefined, 3, 2, 1),
(cb) => cb()
)
q.unshift((cb) => {
setTimeout(() => {
cb(undefined, 'string')
}, 10)
})
try {
await q.start()
t.pass()
} catch (err) {
t.notOk(err)
}
[
['string'],
[42],
[3, 2, 1],
[]
].forEach((expected, i) => {
t.arrayEqual(expected, q.results[i])
})
});