multiunshift.js 915 B

12345678910111213141516171819202122232425262728293031
  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. test('multiunshift', function (t) {
  8. t.plan(1);
  9. var a = split();
  10. var b = through.obj(function (row, enc, next) {
  11. this.push(JSON.parse(row));
  12. next();
  13. });
  14. var c = through.obj(function (row, enc, next) { this.push(row.x); next() });
  15. var d = through.obj(function (x, enc, next) { this.push(x * 111); next() });
  16. var e = stringify();
  17. var stream = pipeline();
  18. stream.unshift(d, e);
  19. stream.unshift(a, b, c);
  20. stream.pipe(concat(function (body) {
  21. t.deepEqual(body.toString(), '[\n333\n,\n444\n,\n555\n]\n');
  22. }));
  23. stream.write('{"x":3}\n');
  24. stream.write('{"x":4}\n');
  25. stream.write('{"x":5}');
  26. stream.end();
  27. });