index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. var es = require('event-stream')
  2. var through = require('through2')
  3. var combine = require('..')
  4. var test = require('tape')
  5. test('re-emit error object for old streams', function (test) {
  6. test.plan(1)
  7. var expectedErr = new Error('asplode')
  8. var pipe = combine(
  9. es.through(function(data) {
  10. return this.emit('error', expectedErr)
  11. })
  12. )
  13. pipe.on('error', function (err) {
  14. test.equal(err, expectedErr)
  15. })
  16. pipe.write('pow')
  17. })
  18. test('do not duplicate errors', function (test) {
  19. var errors = 0;
  20. var pipe = combine(
  21. es.through(function(data) {
  22. return this.emit('data', data);
  23. }),
  24. es.through(function(data) {
  25. return this.emit('error', new Error(data));
  26. })
  27. )
  28. pipe.on('error', function(err) {
  29. errors++
  30. test.ok(errors, 'expected error count')
  31. process.nextTick(function () {
  32. return test.end();
  33. })
  34. })
  35. return pipe.write('meh');
  36. })
  37. test('3 pipe do not duplicate errors', function (test) {
  38. var errors = 0;
  39. var pipe = combine(
  40. es.through(function(data) {
  41. return this.emit('data', data);
  42. }),
  43. es.through(function(data) {
  44. return this.emit('error', new Error(data));
  45. }),
  46. es.through()
  47. )
  48. pipe.on('error', function(err) {
  49. errors++
  50. test.ok(errors, 'expected error count')
  51. process.nextTick(function () {
  52. return test.end();
  53. })
  54. })
  55. return pipe.write('meh');
  56. })
  57. test('0 argument through stream', function (test) {
  58. test.plan(3)
  59. var pipe = combine()
  60. , expected = [ 'beep', 'boop', 'robots' ]
  61. pipe.pipe(es.through(function(data) {
  62. test.equal(data.toString('utf8'), expected.shift())
  63. }))
  64. pipe.write('beep')
  65. pipe.write('boop')
  66. pipe.end('robots')
  67. })
  68. test('object mode', function (test) {
  69. test.plan(2)
  70. var pipe = combine.obj()
  71. , expected = [ [4,5,6], {x:5} ]
  72. pipe.pipe(through.obj(function(data, enc, next) {
  73. test.deepEqual(data, expected.shift())
  74. next()
  75. }))
  76. pipe.write([4,5,6])
  77. pipe.write({x:5})
  78. pipe.end()
  79. })