shift.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var pipeline = require('../');
  2. var through = require('through2');
  3. var test = require('tape');
  4. test('shift', function (t) {
  5. var expected = {};
  6. expected.a = [ 3, 4 ];
  7. expected.b = [ 300, 400, 5, 6 ];
  8. expected.c = [ 310, 410, 15, 16 ];
  9. expected.output = [ 155, 205, 15/2, 8 ];
  10. t.plan(2 + 4 + 4 + 4);
  11. var a = through.obj(function (x, enc, next) {
  12. var ex = expected.a.shift();
  13. t.equal(x, ex, 'a');
  14. this.push(x * 100);
  15. next();
  16. });
  17. var b = through.obj(function (x, enc, next) {
  18. var ex = expected.b.shift();
  19. t.equal(x, ex, 'b');
  20. if (expected.b.length === 2) p.shift()
  21. this.push(x + 10);
  22. next();
  23. });
  24. var c = through.obj(function (x, enc, next) {
  25. var ex = expected.c.shift();
  26. t.equal(x, ex, 'c');
  27. this.push(x / 2);
  28. next();
  29. });
  30. var p = pipeline.obj([ a, b, c ]);
  31. p.pipe(through.obj(function (x, enc, next) {
  32. var ex = expected.output.shift();
  33. t.equal(x, ex);
  34. next();
  35. }));
  36. p.write(3);
  37. p.write(4);
  38. p.write(5);
  39. p.write(6);
  40. p.end();
  41. });