Files: 4f27567900a7b5b821bccc74e95bfc96c8233159 / node_modules / pull-cat / test / index.js
3181 bytesRaw
1 | var pull = require('pull-stream') |
2 | var cat = require('../') |
3 | var test = require('tape') |
4 | var Pushable = require('pull-pushable') |
5 | var Abortable = require('pull-abortable') |
6 | |
7 | test('cat', function (t) { |
8 | pull( |
9 | cat([pull.values([1,2,3]), pull.values([4,5,6])]), |
10 | pull.collect(function (err, ary) { |
11 | console.log(err, ary) |
12 | t.notOk(err) |
13 | t.deepEqual(ary, [1,2,3,4,5,6]) |
14 | t.end() |
15 | }) |
16 | ) |
17 | }) |
18 | |
19 | test('cat - with empty', function (t) { |
20 | pull( |
21 | cat([pull.values([1,2,3]), null, pull.values([4,5,6])]), |
22 | pull.collect(function (err, ary) { |
23 | console.log(err, ary) |
24 | t.notOk(err) |
25 | t.deepEqual(ary, [1,2,3,4,5,6]) |
26 | t.end() |
27 | }) |
28 | ) |
29 | }) |
30 | |
31 | test('cat - with empty stream', function (t) { |
32 | var ended = false |
33 | var justEnd = function (err, cb) { ended = true; cb(true) } |
34 | |
35 | pull( |
36 | cat([pull.values([1,2,3]), justEnd, pull.values([4,5,6])]), |
37 | pull.collect(function (err, ary) { |
38 | console.log(err, ary) |
39 | t.ok(ended) |
40 | t.notOk(err) |
41 | t.deepEqual(ary, [1,2,3,4,5,6]) |
42 | t.end() |
43 | }) |
44 | ) |
45 | }) |
46 | |
47 | |
48 | |
49 | test('abort - with empty', function (t) { |
50 | pull( |
51 | cat([pull.values([1,2,3]), null, pull.values([4,5,6])]), |
52 | function (read) { |
53 | read(true, function (err) { |
54 | t.equal(err, true) |
55 | t.end() |
56 | }) |
57 | } |
58 | ) |
59 | }) |
60 | |
61 | test('error', function (t) { |
62 | var err = new Error('test error') |
63 | pull( |
64 | cat([pull.values([1,2,3]), function (_, cb) { |
65 | cb(err) |
66 | }]), |
67 | pull.collect(function (_err) { |
68 | console.log('COLLECT END', _err) |
69 | t.equal(_err, err) |
70 | t.end() |
71 | }) |
72 | ) |
73 | }) |
74 | |
75 | test('abort stalled', function (t) { |
76 | var err = new Error('intentional'), n = 2 |
77 | var abortable = Abortable() |
78 | var pushable = Pushable(function (_err) { |
79 | t.equal(_err, err) |
80 | next() |
81 | }) |
82 | |
83 | pushable.push(4) |
84 | |
85 | pull( |
86 | cat([pull.values([1,2,3]), undefined, pushable]), |
87 | abortable, |
88 | pull.drain(function (item) { |
89 | if(item == 4) |
90 | process.nextTick(function () { |
91 | abortable.abort(err) |
92 | }) |
93 | }, function (err) { |
94 | next() |
95 | }) |
96 | ) |
97 | |
98 | function next () { |
99 | if(--n) return |
100 | t.end() |
101 | } |
102 | }) |
103 | |
104 | test('abort empty', function (t) { |
105 | cat([])(true, function (end) { |
106 | t.equal(end, true) |
107 | t.end() |
108 | }) |
109 | }) |
110 | |
111 | test('error + undefined', function (t) { |
112 | var err = new Error('test error') |
113 | pull( |
114 | cat([pull.values([1,2,3]), function (_, cb) { |
115 | cb(err) |
116 | }, undefined]), |
117 | pull.collect(function (_err) { |
118 | t.equal(_err, err) |
119 | t.end() |
120 | }) |
121 | ) |
122 | }) |
123 | |
124 | test('take cat', function (t) { |
125 | pull( |
126 | cat([ |
127 | pull(pull.values([1,2,3]), pull.take(2)), |
128 | pull(pull.values([8,7,6,5]), pull.take(3)), |
129 | ]), |
130 | pull.collect(function (err, data) { |
131 | t.error(err) |
132 | t.deepEqual(data, [1,2,8,7,6]) |
133 | t.end() |
134 | }) |
135 | ) |
136 | }) |
137 | |
138 | test('abort streams after error', function (t) { |
139 | var err = new Error('test error') |
140 | var aborted = false |
141 | pull( |
142 | cat([pull.values([1,2,3]), function (_, cb) { |
143 | cb(err) |
144 | }, function (_err, cb) { |
145 | //this stream should be aborted. |
146 | aborted = true |
147 | t.strictEqual(_err, err) |
148 | cb() |
149 | }]), |
150 | pull.collect(function (_err) { |
151 | t.equal(aborted, true) |
152 | t.equal(_err, err) |
153 | t.end() |
154 | }) |
155 | ) |
156 | }) |
157 | |
158 | |
159 | |
160 |
Built with git-ssb-web