mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 17:57:53 +00:00

fs.ReadStream / fs.WriteStream destroy([error]) function should emit 'error' event if `error` is set. PR-URL: https://github.com/nodejs/node/pull/19735 Fixes: https://github.com/nodejs/node/issues/19727 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
21 lines
491 B
JavaScript
21 lines
491 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
test(fs.createReadStream(__filename));
|
|
test(fs.createWriteStream(`${tmpdir.path}/dummy`));
|
|
|
|
function test(stream) {
|
|
const err = new Error('DESTROYED');
|
|
stream.on('open', function() {
|
|
stream.destroy(err);
|
|
});
|
|
stream.on('error', common.mustCall(function(err_) {
|
|
assert.strictEqual(err_, err);
|
|
}));
|
|
}
|