Skip to content

Commit

Permalink
process-exit-code-cases.js: update zeroExitWithUncaughtHandler and ch…
Browse files Browse the repository at this point in the history
…angeCodeInUncaughtHandler

cannot use `node:assert` module in cases where `uncaughtException` handler is registered as an failure will be eaten by it
  • Loading branch information
nektro authored Jul 25, 2024
1 parent 852a1a6 commit 8c6ae88
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions test/fixtures/process-exit-code-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ function getTestCases(isWorker = false) {

function zeroExitWithUncaughtHandler() {
process.on('exit', (code) => {
assert.strictEqual(process.exitCode, 0);
assert.strictEqual(code, 0);
if (code !== 0) {
console.log('wrong code! expected 0; got', code);
process.exit(99);
}
if (process.exitCode !== undefined) {
console.log('wrong exitCode! expected undefined; got', process.exitCode);
process.exit(99);
}
});
process.on('uncaughtException', () => { });
throw new Error('ok');
Expand All @@ -73,8 +79,14 @@ function getTestCases(isWorker = false) {

function changeCodeInUncaughtHandler() {
process.on('exit', (code) => {
assert.strictEqual(process.exitCode, 97);
assert.strictEqual(code, 97);
if (code !== 97) {
console.log('wrong code! expected 97; got', code);
process.exit(99);
}
if (process.exitCode !== 97) {
console.log('wrong exitCode! expected 97; got', process.exitCode);
process.exit(99);
}
});
process.on('uncaughtException', () => {
process.exitCode = 97;
Expand Down

0 comments on commit 8c6ae88

Please sign in to comment.