mirror of https://github.com/nodejs/node.git
test: do not swallow uncaughtException errors in exit code tests
PR-URL: https://github.com/nodejs/node/pull/54039 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>pull/54039/head
parent
cf9a8140aa
commit
d7941b24ae
|
@ -62,23 +62,25 @@ function getTestCases(isWorker = false) {
|
||||||
cases.push({ func: changeCodeInsideExit, result: 99 });
|
cases.push({ func: changeCodeInsideExit, result: 99 });
|
||||||
|
|
||||||
function zeroExitWithUncaughtHandler() {
|
function zeroExitWithUncaughtHandler() {
|
||||||
|
const noop = () => { };
|
||||||
process.on('exit', (code) => {
|
process.on('exit', (code) => {
|
||||||
assert.strictEqual(process.exitCode, 0);
|
process.off('uncaughtException', noop);
|
||||||
|
assert.strictEqual(process.exitCode, undefined);
|
||||||
assert.strictEqual(code, 0);
|
assert.strictEqual(code, 0);
|
||||||
});
|
});
|
||||||
process.on('uncaughtException', () => { });
|
process.on('uncaughtException', noop);
|
||||||
throw new Error('ok');
|
throw new Error('ok');
|
||||||
}
|
}
|
||||||
cases.push({ func: zeroExitWithUncaughtHandler, result: 0 });
|
cases.push({ func: zeroExitWithUncaughtHandler, result: 0 });
|
||||||
|
|
||||||
function changeCodeInUncaughtHandler() {
|
function changeCodeInUncaughtHandler() {
|
||||||
|
const modifyExitCode = () => { process.exitCode = 97; };
|
||||||
process.on('exit', (code) => {
|
process.on('exit', (code) => {
|
||||||
|
process.off('uncaughtException', modifyExitCode);
|
||||||
assert.strictEqual(process.exitCode, 97);
|
assert.strictEqual(process.exitCode, 97);
|
||||||
assert.strictEqual(code, 97);
|
assert.strictEqual(code, 97);
|
||||||
});
|
});
|
||||||
process.on('uncaughtException', () => {
|
process.on('uncaughtException', modifyExitCode);
|
||||||
process.exitCode = 97;
|
|
||||||
});
|
|
||||||
throw new Error('ok');
|
throw new Error('ok');
|
||||||
}
|
}
|
||||||
cases.push({ func: changeCodeInUncaughtHandler, result: 97 });
|
cases.push({ func: changeCodeInUncaughtHandler, result: 97 });
|
||||||
|
|
Loading…
Reference in New Issue