Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80540 views
1
var pipeline = require('../');
2
var through = require('through2');
3
var stringify = require('JSONStream').stringify;
4
var split = require('split');
5
var concat = require('concat-stream');
6
var test = require('tape');
7
8
test('multiunshift', function (t) {
9
t.plan(1);
10
11
var a = split();
12
var b = through.obj(function (row, enc, next) {
13
this.push(JSON.parse(row));
14
next();
15
});
16
var c = through.obj(function (row, enc, next) { this.push(row.x); next() });
17
var d = through.obj(function (x, enc, next) { this.push(x * 111); next() });
18
var e = stringify();
19
20
var stream = pipeline();
21
stream.unshift(d, e);
22
stream.unshift(a, b, c);
23
stream.pipe(concat(function (body) {
24
t.deepEqual(body.toString(), '[\n333\n,\n444\n,\n555\n]\n');
25
}));
26
27
stream.write('{"x":3}\n');
28
stream.write('{"x":4}\n');
29
stream.write('{"x":5}');
30
stream.end();
31
});
32
33