Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80551 views
1
var es = require('event-stream')
2
var through = require('through2')
3
var combine = require('..')
4
var test = require('tape')
5
6
test('re-emit error object for old streams', function (test) {
7
test.plan(1)
8
9
var expectedErr = new Error('asplode')
10
11
var pipe = combine(
12
es.through(function(data) {
13
return this.emit('error', expectedErr)
14
})
15
)
16
17
pipe.on('error', function (err) {
18
test.equal(err, expectedErr)
19
})
20
21
pipe.write('pow')
22
})
23
24
test('do not duplicate errors', function (test) {
25
26
var errors = 0;
27
var pipe = combine(
28
es.through(function(data) {
29
return this.emit('data', data);
30
}),
31
es.through(function(data) {
32
return this.emit('error', new Error(data));
33
})
34
)
35
36
pipe.on('error', function(err) {
37
errors++
38
test.ok(errors, 'expected error count')
39
process.nextTick(function () {
40
return test.end();
41
})
42
})
43
44
return pipe.write('meh');
45
})
46
47
test('3 pipe do not duplicate errors', function (test) {
48
49
var errors = 0;
50
var pipe = combine(
51
es.through(function(data) {
52
return this.emit('data', data);
53
}),
54
es.through(function(data) {
55
return this.emit('error', new Error(data));
56
}),
57
es.through()
58
)
59
60
pipe.on('error', function(err) {
61
errors++
62
test.ok(errors, 'expected error count')
63
process.nextTick(function () {
64
return test.end();
65
})
66
})
67
68
return pipe.write('meh');
69
70
})
71
72
test('0 argument through stream', function (test) {
73
test.plan(3)
74
var pipe = combine()
75
, expected = [ 'beep', 'boop', 'robots' ]
76
77
pipe.pipe(es.through(function(data) {
78
test.equal(data.toString('utf8'), expected.shift())
79
}))
80
pipe.write('beep')
81
pipe.write('boop')
82
pipe.end('robots')
83
})
84
85
test('object mode', function (test) {
86
test.plan(2)
87
var pipe = combine.obj()
88
, expected = [ [4,5,6], {x:5} ]
89
90
pipe.pipe(through.obj(function(data, enc, next) {
91
test.deepEqual(data, expected.shift())
92
next()
93
}))
94
pipe.write([4,5,6])
95
pipe.write({x:5})
96
pipe.end()
97
})
98
99
100