Sha256: d95df67f98f0814c6cd8d40d6e1dc392ef6fbd46714329e107136e7710ff3ccd

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

'use strict';
require('../common');
var assert = require('assert');
var stream = require('stream');

{
  let count = 1000;

  const source = new stream.Readable();
  source._read = function(n) {
    n = Math.min(count, n);
    count -= n;
    source.push(Buffer.allocUnsafe(n));
  };

  let unpipedDest;
  source.unpipe = function(dest) {
    unpipedDest = dest;
    stream.Readable.prototype.unpipe.call(this, dest);
  };

  const dest = new stream.Writable();
  dest._write = function(chunk, encoding, cb) {
    cb();
  };

  source.pipe(dest);

  let gotErr = null;
  dest.on('error', function(err) {
    gotErr = err;
  });

  let unpipedSource;
  dest.on('unpipe', function(src) {
    unpipedSource = src;
  });

  const err = new Error('This stream turned into bacon.');
  dest.emit('error', err);
  assert.strictEqual(gotErr, err);
  assert.strictEqual(unpipedSource, source);
  assert.strictEqual(unpipedDest, dest);
}

{
  let count = 1000;

  const source = new stream.Readable();
  source._read = function(n) {
    n = Math.min(count, n);
    count -= n;
    source.push(Buffer.allocUnsafe(n));
  };

  let unpipedDest;
  source.unpipe = function(dest) {
    unpipedDest = dest;
    stream.Readable.prototype.unpipe.call(this, dest);
  };

  const dest = new stream.Writable();
  dest._write = function(chunk, encoding, cb) {
    cb();
  };

  source.pipe(dest);

  let unpipedSource;
  dest.on('unpipe', function(src) {
    unpipedSource = src;
  });

  const err = new Error('This stream turned into bacon.');

  let gotErr = null;
  try {
    dest.emit('error', err);
  } catch (e) {
    gotErr = e;
  }
  assert.strictEqual(gotErr, err);
  assert.strictEqual(unpipedSource, source);
  assert.strictEqual(unpipedDest, dest);
}

Version data entries

5 entries across 4 versions & 1 rubygems

Version Path
node-compiler-0.9.1 vendor/node/test/parallel/test-stream2-pipe-error-handling.js
node-compiler-0.9.0 vendor/node-v7.2.1/test/parallel/test-stream2-pipe-error-handling.js
node-compiler-0.8.0 vendor/node-v7.2.0/test/parallel/test-stream2-pipe-error-handling.js
node-compiler-0.7.0 vendor/node-v6.9.1/test/parallel/test-stream2-pipe-error-handling.js
node-compiler-0.7.0 vendor/node-v7.1.0/test/parallel/test-stream2-pipe-error-handling.js