combiner_stream.js 889 B

1234567891011121314151617181920212223242526272829
  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 returned stream', 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([ a, b, c, d, e ]);
  18. stream.pipe(concat(function (body) {
  19. t.deepEqual(body.toString(), '[\n333\n,\n444\n,\n555\n]\n');
  20. }));
  21. stream.write('{"x":3}\n');
  22. stream.write('{"x":4}\n');
  23. stream.write('{"x":5}');
  24. stream.end();
  25. });