combiner.js 926 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('combiner', 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 input = through();
  18. var output = through();
  19. output.pipe(concat(function (body) {
  20. t.deepEqual(body.toString(), '[\n333\n,\n444\n,\n555\n]\n');
  21. }));
  22. pipeline([ input, a, b, c, d, e, output ]);
  23. input.write('{"x":3}\n');
  24. input.write('{"x":4}\n');
  25. input.write('{"x":5}');
  26. input.end();
  27. });