1 | var tape = require('tape')
|
2 | var through = require('through2')
|
3 | var pumpify = require('./')
|
4 |
|
5 | tape('basic', function(t) {
|
6 | t.plan(3)
|
7 |
|
8 | var pipeline = pumpify(
|
9 | through(function(data, enc, cb) {
|
10 | t.same(data.toString(), 'hello')
|
11 | cb(null, data.toString().toUpperCase())
|
12 | }),
|
13 | through(function(data, enc, cb) {
|
14 | t.same(data.toString(), 'HELLO')
|
15 | cb(null, data.toString().toLowerCase())
|
16 | })
|
17 | )
|
18 |
|
19 | pipeline.write('hello')
|
20 | pipeline.on('data', function(data) {
|
21 | t.same(data.toString(), 'hello')
|
22 | t.end()
|
23 | })
|
24 | })
|
25 |
|
26 | tape('3 times', function(t) {
|
27 | t.plan(4)
|
28 |
|
29 | var pipeline = pumpify(
|
30 | through(function(data, enc, cb) {
|
31 | t.same(data.toString(), 'hello')
|
32 | cb(null, data.toString().toUpperCase())
|
33 | }),
|
34 | through(function(data, enc, cb) {
|
35 | t.same(data.toString(), 'HELLO')
|
36 | cb(null, data.toString().toLowerCase())
|
37 | }),
|
38 | through(function(data, enc, cb) {
|
39 | t.same(data.toString(), 'hello')
|
40 | cb(null, data.toString().toUpperCase())
|
41 | })
|
42 | )
|
43 |
|
44 | pipeline.write('hello')
|
45 | pipeline.on('data', function(data) {
|
46 | t.same(data.toString(), 'HELLO')
|
47 | t.end()
|
48 | })
|
49 | })
|
50 |
|
51 | tape('destroy', function(t) {
|
52 | var test = through()
|
53 | test.destroy = function() {
|
54 | t.ok(true)
|
55 | t.end()
|
56 | }
|
57 |
|
58 | var pipeline = pumpify(through(), test)
|
59 |
|
60 | pipeline.destroy()
|
61 | })
|
62 |
|
63 | tape('close', function(t) {
|
64 | var test = through()
|
65 | var pipeline = pumpify(through(), test)
|
66 |
|
67 | pipeline.on('error', function(err) {
|
68 | t.same(err.message, 'lol')
|
69 | t.end()
|
70 | })
|
71 |
|
72 | test.emit('error', new Error('lol'))
|
73 | }) |
\ | No newline at end of file |