Skip to content

Commit

Permalink
[fix] make test/create-websocket-stream.test.js compatible with domains
Browse files Browse the repository at this point in the history
Fix a failure in test/create-websocket-stream.test.js if the node: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 will cause node:domain to prepend its own
handler for the same event, which confused the test.

Fixes: websockets#2124
  • Loading branch information
mvduin committed Mar 9, 2023
1 parent 41dc56a commit 7992442
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 7992442

Please sign in to comment.