mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.8 KiB
85 lines
1.8 KiB
12 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
var stream = require('stream');
|
||
|
|
||
|
(function testErrorListenerCatches() {
|
||
|
var count = 1000;
|
||
|
|
||
|
var source = new stream.Readable();
|
||
12 years ago
|
source._read = function(n) {
|
||
12 years ago
|
n = Math.min(count, n);
|
||
|
count -= n;
|
||
12 years ago
|
source.push(new Buffer(n));
|
||
12 years ago
|
};
|
||
|
|
||
|
var unpipedDest;
|
||
|
source.unpipe = function(dest) {
|
||
|
unpipedDest = dest;
|
||
|
stream.Readable.prototype.unpipe.call(this, dest);
|
||
|
};
|
||
|
|
||
|
var dest = new stream.Writable();
|
||
12 years ago
|
dest._write = function(chunk, encoding, cb) {
|
||
12 years ago
|
cb();
|
||
|
};
|
||
|
|
||
|
source.pipe(dest);
|
||
|
|
||
|
var gotErr = null;
|
||
|
dest.on('error', function(err) {
|
||
|
gotErr = err;
|
||
|
});
|
||
|
|
||
|
var unpipedSource;
|
||
|
dest.on('unpipe', function(src) {
|
||
|
unpipedSource = src;
|
||
|
});
|
||
|
|
||
|
var err = new Error('This stream turned into bacon.');
|
||
|
dest.emit('error', err);
|
||
|
assert.strictEqual(gotErr, err);
|
||
|
assert.strictEqual(unpipedSource, source);
|
||
|
assert.strictEqual(unpipedDest, dest);
|
||
|
})();
|
||
|
|
||
|
(function testErrorWithoutListenerThrows() {
|
||
|
var count = 1000;
|
||
|
|
||
|
var source = new stream.Readable();
|
||
12 years ago
|
source._read = function(n) {
|
||
12 years ago
|
n = Math.min(count, n);
|
||
|
count -= n;
|
||
12 years ago
|
source.push(new Buffer(n));
|
||
12 years ago
|
};
|
||
|
|
||
|
var unpipedDest;
|
||
|
source.unpipe = function(dest) {
|
||
|
unpipedDest = dest;
|
||
|
stream.Readable.prototype.unpipe.call(this, dest);
|
||
|
};
|
||
|
|
||
|
var dest = new stream.Writable();
|
||
12 years ago
|
dest._write = function(chunk, encoding, cb) {
|
||
12 years ago
|
cb();
|
||
|
};
|
||
|
|
||
|
source.pipe(dest);
|
||
|
|
||
|
var unpipedSource;
|
||
|
dest.on('unpipe', function(src) {
|
||
|
unpipedSource = src;
|
||
|
});
|
||
|
|
||
|
var err = new Error('This stream turned into bacon.');
|
||
|
|
||
|
var gotErr = null;
|
||
|
try {
|
||
|
dest.emit('error', err);
|
||
|
} catch (e) {
|
||
|
gotErr = e;
|
||
|
}
|
||
|
assert.strictEqual(gotErr, err);
|
||
|
assert.strictEqual(unpipedSource, source);
|
||
|
assert.strictEqual(unpipedDest, dest);
|
||
|
})();
|