-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
89 lines (73 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var peek = require('./')
var tape = require('tape')
var concat = require('concat-stream')
var through = require('through2')
var uppercase = function(data, enc, cb) {
cb(null, data.toString().toUpperCase())
}
tape('swap to uppercase', function(t) {
var p = peek(function(data, swap) {
swap(null, through(uppercase))
})
p.pipe(concat(function(data) {
t.same(data.toString(), 'HELLO\nWORLD\n')
t.end()
}))
p.write('hello\n')
p.write('world\n')
p.end()
})
tape('swap to uppercase no newline', function(t) {
var p = peek(function(data, swap) {
swap(null, through(uppercase))
})
p.pipe(concat(function(data) {
t.same(data.toString(), 'HELLOWORLD')
t.end()
}))
p.write('hello')
p.write('world')
p.end()
})
tape('swap to uppercase async', function(t) {
var p = peek(function(data, swap) {
setTimeout(function() {
swap(null, through(uppercase))
}, 100)
})
p.pipe(concat(function(data) {
t.same(data.toString(), 'HELLO\nWORLD\n')
t.end()
}))
p.write('hello\n')
p.write('world\n')
p.end()
})
tape('swap to error', function(t) {
var p = peek(function(data, swap) {
swap(new Error('nogo'))
})
p.on('error', function(err) {
t.ok(err)
t.same(err.message, 'nogo')
t.end()
})
p.write('hello\n')
p.write('world\n')
p.end()
})
tape('swap to error async', function(t) {
var p = peek(function(data, swap) {
setTimeout(function() {
swap(new Error('nogo'))
}, 100)
})
p.on('error', function(err) {
t.ok(err)
t.same(err.message, 'nogo')
t.end()
})
p.write('hello\n')
p.write('world\n')
p.end()
})