Skip to content

Commit

Permalink
[test] Fix failing test when using the domain module (#2126)
Browse files Browse the repository at this point in the history
Fix a failure in `test/create-websocket-stream.test.js` if the domain
module is loaded (e.g. due to `NODE_OPTIONS` in environment).

The cause of the failure was that installing an `'uncaughtException'`
event handler on `process` causes the domain module to prepend its own
handler for the same event, which confused the test.

Fixes #2124
  • Loading branch information
mvduin committed Mar 9, 2023
1 parent 41dc56a commit b4b9d5a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/create-websocket-stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,14 @@ describe('createWebSocketStream', () => {
ws._socket.write(Buffer.from([0x85, 0x00]));
});

assert.strictEqual(process.listenerCount('uncaughtException'), 1);
assert.strictEqual(
process.listenerCount('uncaughtException'),
EventEmitter.usingDomains ? 2 : 1
);

const [listener] = process.listeners('uncaughtException');
const listener = process.listeners('uncaughtException').pop();

process.removeAllListeners('uncaughtException');
process.removeListener('uncaughtException', listener);
process.once('uncaughtException', (err) => {
assert.ok(err instanceof Error);
assert.strictEqual(
Expand Down

0 comments on commit b4b9d5a

Please sign in to comment.