-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
65 lines (53 loc) · 1.5 KB
/
test.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
var tape = require('tape')
var from = require('from2')
var concat = require('concat-stream')
var multi = require('./')
tape('reads from both streams', function (t) {
var a = from.obj(['a1', 'b1', 'c1'])
var b = from.obj(['a2', 'b2', 'c2'])
var rs = multi.obj([a, b])
rs.pipe(concat({encoding: 'list'}, function (list) {
t.same(list.sort(), ['a1', 'a2', 'b1', 'b2', 'c1', 'c2'], 'multi output')
t.end()
}))
})
tape('reads from both streams different size', function (t) {
var a = from.obj(['a1'])
var b = from.obj(['a2', 'b2', 'c2'])
var rs = multi.obj([a, b])
rs.pipe(concat({encoding: 'list'}, function (list) {
t.same(list.sort(), ['a1', 'a2', 'b2', 'c2'], 'multi output')
t.end()
}))
})
tape('one can be slow', function (t) {
var once = true
var a = from.obj(function (size, cb) {
setTimeout(function () {
if (once) {
once = false
cb(null, 'slow')
} else {
cb(null, null)
}
}, 200)
})
var b = from.obj(['fast1', 'fast2', 'fast3'])
var rs = multi.obj([a, b])
rs.pipe(concat({encoding: 'list'}, function (list) {
t.same(list, ['fast1', 'fast2', 'fast3', 'slow'], 'multi output')
t.end()
}))
})
tape('add later', function (t) {
var a = from.obj(['a1'])
var b = from.obj(['a2', 'b2', 'c2'])
var rs = multi.obj([b])
rs.once('data', function () {
rs.add(a)
})
rs.pipe(concat({encoding: 'list'}, function (list) {
t.same(list.sort(), ['a1', 'a2', 'b2', 'c2'], 'multi output')
t.end()
}))
})