From b4b9d5a76e8c105fdeec64232fb6f12b6f88416d Mon Sep 17 00:00:00 2001 From: Matthijs van Duin Date: Thu, 9 Mar 2023 21:24:34 +0100 Subject: [PATCH] [test] Fix failing test when using the domain module (#2126) 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 --- test/create-websocket-stream.test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/create-websocket-stream.test.js b/test/create-websocket-stream.test.js index 4d51958cd..572f5c4f2 100644 --- a/test/create-websocket-stream.test.js +++ b/test/create-websocket-stream.test.js @@ -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(