node/test/parallel/test-wrap-js-stream-exceptions.js
Robert Nagy 3de5eae6db stream: invoke callback before emitting error always
Ensure the callback is always invoked before emitting
the error in both sync and async case.

PR-URL: https://github.com/nodejs/node/pull/29293
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-09-27 15:45:17 -07:00

24 lines
604 B
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const JSStreamWrap = require('internal/js_stream_socket');
const { Duplex } = require('stream');
process.once('uncaughtException', common.mustCall((err) => {
assert.strictEqual(err.message, 'exception!');
}));
const socket = new JSStreamWrap(new Duplex({
read: common.mustNotCall(),
write: common.mustCall((buffer, data, cb) => {
throw new Error('exception!');
})
}));
socket.end('foo');
socket.on('error', common.expectsError({
type: Error,
message: 'write EPROTO'
}));