pipeline.js 1003 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var test = require('tape');
  2. var pipeline = require('..').pipeline;
  3. var stream = require('..');
  4. var Buffer = require('safe-buffer').Buffer;
  5. test('supports pipeline', function(t) {
  6. t.plan(4);
  7. var readable = new stream.Readable({
  8. read: function () {
  9. this.push(Buffer.from('chunk', 'ascii'));
  10. }
  11. });
  12. var transform1 = new stream.Transform({
  13. transform: function (chunk, enc, cb) {
  14. cb(new Error('fail'));
  15. }
  16. });
  17. var transform2 = new stream.PassThrough();
  18. transform2.on('close', function () {
  19. t.pass('transform2.close called');
  20. });
  21. var writable = new stream.Writable({
  22. write: function (chunk, enc, cb) { cb(); }
  23. });
  24. writable.on('close', function () {
  25. t.pass('writable.close called');
  26. });
  27. pipeline(
  28. readable,
  29. transform1,
  30. transform2,
  31. writable,
  32. function(err) {
  33. t.ok(err);
  34. t.equal(err.message, 'fail');
  35. });
  36. });