mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 13:09:42 +00:00

Changes so that the end() callback behaves the same way in relation to _final as write() does to _write/_writev. PR-URL: https://github.com/nodejs/node/pull/34101 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const stream = require('stream');
|
|
|
|
{
|
|
// Invoke end callback on failure.
|
|
const writable = new stream.Writable();
|
|
|
|
writable._write = (chunk, encoding, cb) => {
|
|
process.nextTick(cb, new Error('kaboom'));
|
|
};
|
|
|
|
writable.on('error', common.mustCall((err) => {
|
|
assert.strictEqual(err.message, 'kaboom');
|
|
}));
|
|
writable.write('asd');
|
|
writable.end(common.mustCall((err) => {
|
|
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
|
|
}));
|
|
writable.end(common.mustCall((err) => {
|
|
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
|
|
}));
|
|
}
|
|
|
|
{
|
|
// Don't invoke end callback twice
|
|
const writable = new stream.Writable();
|
|
|
|
writable._write = (chunk, encoding, cb) => {
|
|
process.nextTick(cb);
|
|
};
|
|
|
|
let called = false;
|
|
writable.end('asd', common.mustCall((err) => {
|
|
called = true;
|
|
assert.strictEqual(err, undefined);
|
|
}));
|
|
|
|
writable.on('error', common.mustCall((err) => {
|
|
assert.strictEqual(err.message, 'kaboom');
|
|
}));
|
|
writable.on('finish', common.mustCall(() => {
|
|
assert.strictEqual(called, true);
|
|
writable.emit('error', new Error('kaboom'));
|
|
}));
|
|
}
|