Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80540 views
1
var pipeline = require('../');
2
var through = require('through2');
3
var split = require('split');
4
var concat = require('concat-stream');
5
var test = require('tape');
6
7
test('unshift', function (t) {
8
var expected = {};
9
expected.a = [ 5, 6 ];
10
expected.b = [ 3, 4, 500, 600 ];
11
expected.c = [ 13, 14, 510, 610 ];
12
expected.output = [ 13/2, 7, 255, 305 ];
13
14
t.plan(2 + 4 + 4 + 4);
15
16
var a = through.obj(function (x, enc, next) {
17
var ex = expected.a.shift();
18
t.equal(x, ex, 'a');
19
this.push(x * 100);
20
next();
21
});
22
var b = through.obj(function (x, enc, next) {
23
var ex = expected.b.shift();
24
t.equal(x, ex, 'b');
25
if (expected.b.length === 2) p.unshift(a)
26
this.push(x + 10);
27
next();
28
});
29
var c = through.obj(function (x, enc, next) {
30
var ex = expected.c.shift();
31
t.equal(x, ex, 'c');
32
this.push(x / 2);
33
next();
34
});
35
36
var p = pipeline.obj([ b, c ]);
37
p.pipe(through.obj(function (x, enc, next) {
38
var ex = expected.output.shift();
39
t.equal(x, ex);
40
next();
41
}));
42
43
p.write(3);
44
p.write(4);
45
p.write(5);
46
p.write(6);
47
p.end();
48
});
49
50