-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
75 lines (59 loc) · 1.61 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
66
67
68
69
70
71
72
73
74
75
const pumpcat = require('./index')
const assert = require('assert')
const { Readable, PassThrough } = require('stream')
const testWithOneChunk = () => {
const rs = new Readable
const pass = new PassThrough()
pumpcat(rs, pass, function (err, data) {
assert.equal(data.toString(), 'woot')
})
rs.push('woot')
rs.push(null)
}
const testWithTwoChunks = () => {
const rs = new Readable
const pass = new PassThrough()
pumpcat(rs, pass, function (err, data) {
assert(data.toString(), 'wootfoot')
})
rs.push('woot')
rs.push('foot')
rs.push(null)
}
const testWithOneError = () => {
const rs = new Readable
const pass = new PassThrough()
const msg = 'haha fooled you!'
pumpcat(rs, pass, function (err, data) {
assert.equal(err.message, msg)
})
rs.push('woot')
rs.emit('error', new Error(msg))
}
const testWithTwoErrorsOnOneStream = () => {
const rs = new Readable
const pass = new PassThrough()
const msg = 'haha fooled you!'
pumpcat(rs, pass, function (err, data) {
assert.equal(err.message, msg)
})
rs.push('woot')
rs.emit('error', new Error(msg))
rs.emit('error', new Error('i should be not be reached'))
}
const testWithTwoErrorsOnTwoStreams = () => {
const rs = new Readable
const pass = new PassThrough()
const msg = 'haha fooled you!'
pumpcat(rs, pass, function (err, data) {
assert.equal(err.message, msg)
})
rs.push('woot')
pass.emit('error', new Error(msg))
rs.emit('error', new Error('i should be not be reached'))
}
testWithOneChunk()
testWithTwoChunks()
testWithOneError()
testWithTwoErrorsOnOneStream()
testWithTwoErrorsOnTwoStreams()