From bd996bf694d71543ec8a452b5c40939ba37f0ebd Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 25 Jul 2024 03:42:11 -0700 Subject: [PATCH] test: do not swallow uncaughtException errors in exit code tests PR-URL: https://github.com/nodejs/node/pull/54039 Reviewed-By: Rich Trott Reviewed-By: James M Snell --- test/common/process-exit-code-cases.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/common/process-exit-code-cases.js b/test/common/process-exit-code-cases.js index 4649b6f94201fc..54cfe2655b2058 100644 --- a/test/common/process-exit-code-cases.js +++ b/test/common/process-exit-code-cases.js @@ -62,23 +62,25 @@ function getTestCases(isWorker = false) { cases.push({ func: changeCodeInsideExit, result: 99 }); function zeroExitWithUncaughtHandler() { + const noop = () => { }; process.on('exit', (code) => { - assert.strictEqual(process.exitCode, 0); + process.off('uncaughtException', noop); + assert.strictEqual(process.exitCode, undefined); assert.strictEqual(code, 0); }); - process.on('uncaughtException', () => { }); + process.on('uncaughtException', noop); throw new Error('ok'); } cases.push({ func: zeroExitWithUncaughtHandler, result: 0 }); function changeCodeInUncaughtHandler() { + const modifyExitCode = () => { process.exitCode = 97; }; process.on('exit', (code) => { + process.off('uncaughtException', modifyExitCode); assert.strictEqual(process.exitCode, 97); assert.strictEqual(code, 97); }); - process.on('uncaughtException', () => { - process.exitCode = 97; - }); + process.on('uncaughtException', modifyExitCode); throw new Error('ok'); } cases.push({ func: changeCodeInUncaughtHandler, result: 97 });