Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: do not swallow uncaughtException errors in exit code tests
PR-URL: #54039
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
nektro authored and Trott committed Jul 29, 2024
commit d7941b24ae6d3e647b0b1e9e543a01ad370b1a08
12 changes: 7 additions & 5 deletions test/common/process-exit-code-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down