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('push', function (t) {
8
var expected = {};
9
expected.first = [ 333, 444, 555, 666, 777 ];
10
expected.second = [ 6.66, 7.77 ];
11
expected.output = [ 3.33, 4.44, 5.55, 3, 2 ];
12
13
t.plan(5 + 2 + 5 + 3);
14
15
var a = split();
16
var b = through.obj(function (row, enc, next) {
17
this.push(JSON.parse(row));
18
next();
19
});
20
var c = through.obj(function (row, enc, next) { this.push(row.x); next() });
21
var d = through.obj(function (x, enc, next) { this.push(x * 111); next() });
22
23
var first = through.obj(function (row, enc, next) {
24
if (expected.first.length === 2) {
25
t.equal(p.length, 5);
26
p.push(second);
27
t.equal(p.length, 6);
28
}
29
30
var ex = expected.first.shift();
31
t.deepEqual(row, ex);
32
33
this.push(row / 100);
34
next();
35
});
36
var second = through.obj(function (row, enc, next) {
37
var ex = expected.second.shift();
38
t.deepEqual(row, ex);
39
this.push(Math.floor(10 - row));
40
next();
41
});
42
43
var p = pipeline.obj([ a, b, c, d, first ]);
44
t.equal(p.length, 5);
45
46
p.pipe(through.obj(function (row, enc, next) {
47
var ex = expected.output.shift();
48
t.deepEqual(row, ex);
49
next();
50
}));
51
52
p.write('{"x":3}\n');
53
p.write('{"x":4}\n');
54
p.write('{"x":5}\n');
55
p.write('{"x":6}\n');
56
p.write('{"x":7}');
57
p.end();
58
});
59
60