node/test/parallel/test-stdout-pipeline-destroy.js
Matteo Collina bdea725bdc process: make stdout and stderr emit 'close' on destroy
Fix: https://github.com/nodejs/node/issues/26550

PR-URL: https://github.com/nodejs/node/pull/26691
Fixes: https://github.com/false
Fixes: https://github.com/nodejs/node/issues/26550
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-03-25 12:29:16 +01:00

32 lines
578 B
JavaScript

'use strict';
const common = require('../common');
const { Transform, Readable, pipeline } = require('stream');
const assert = require('assert');
const reader = new Readable({
read(size) { this.push('foo'); }
});
let count = 0;
const err = new Error('this-error-gets-hidden');
const transform = new Transform({
transform(chunk, enc, cb) {
if (count++ >= 5)
this.emit('error', err);
else
cb(null, count.toString() + '\n');
}
});
pipeline(
reader,
transform,
process.stdout,
common.mustCall((e) => {
assert.strictEqual(e, err);
})
);