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('pop', function (t) {
8
var expected = {};
9
expected.replacer = [ '333', '444' ];
10
11
t.plan(3);
12
13
var a = split();
14
var b = through.obj(function (row, enc, next) {
15
this.push(JSON.parse(row));
16
next();
17
});
18
var c = through.obj(function (row, enc, next) {
19
this.push(row.x);
20
next();
21
});
22
var d = through.obj(function (x, enc, next) {
23
this.push(String(x * 111));
24
next();
25
});
26
var replacer = through(function (buf, enc, next) {
27
var ex = expected.replacer.shift();
28
t.equal(buf.toString(), ex);
29
this.push(buf.toString('hex') + '\n');
30
if (expected.replacer.length === 0) {
31
stream.pop();
32
}
33
next();
34
});
35
36
var stream = pipeline([ a, b, c, d, replacer ]);
37
stream.pipe(concat(function (body) {
38
t.deepEqual(body.toString(), '333333\n343434\n555666');
39
}));
40
41
stream.write('{"x":3}\n');
42
stream.write('{"x":4}\n');
43
stream.write('{"x":5}\n');
44
stream.write('{"x":6}');
45
stream.end();
46
});
47
48