test_runner: cleanup global event listeners after run
PR-URL: https://github.com/nodejs/node/pull/53878 Fixes: https://github.com/nodejs/node/issues/53868 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
cad73dadba
commit
b19a950102
@ -170,8 +170,13 @@ function setup(root) {
|
|||||||
kCancelledByParent));
|
kCancelledByParent));
|
||||||
|
|
||||||
hook.disable();
|
hook.disable();
|
||||||
process.removeListener('unhandledRejection', rejectionHandler);
|
|
||||||
process.removeListener('uncaughtException', exceptionHandler);
|
process.removeListener('uncaughtException', exceptionHandler);
|
||||||
|
process.removeListener('unhandledRejection', rejectionHandler);
|
||||||
|
process.removeListener('beforeExit', exitHandler);
|
||||||
|
if (globalOptions.isTestRunner) {
|
||||||
|
process.removeListener('SIGINT', terminationHandler);
|
||||||
|
process.removeListener('SIGTERM', terminationHandler);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const terminationHandler = () => {
|
const terminationHandler = () => {
|
||||||
|
@ -564,6 +564,7 @@ function run(options = kEmptyObject) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let postRun = () => root.postRun();
|
let postRun = () => root.postRun();
|
||||||
|
let teardown = () => root.harness.teardown();
|
||||||
let filesWatcher;
|
let filesWatcher;
|
||||||
const opts = {
|
const opts = {
|
||||||
__proto__: null,
|
__proto__: null,
|
||||||
@ -578,6 +579,7 @@ function run(options = kEmptyObject) {
|
|||||||
if (watch) {
|
if (watch) {
|
||||||
filesWatcher = watchFiles(testFiles, opts);
|
filesWatcher = watchFiles(testFiles, opts);
|
||||||
postRun = undefined;
|
postRun = undefined;
|
||||||
|
teardown = undefined;
|
||||||
}
|
}
|
||||||
const runFiles = () => {
|
const runFiles = () => {
|
||||||
root.harness.bootstrapComplete = true;
|
root.harness.bootstrapComplete = true;
|
||||||
@ -589,7 +591,8 @@ function run(options = kEmptyObject) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
PromisePrototypeThen(PromisePrototypeThen(PromiseResolve(setup?.(root.reporter)), runFiles), postRun);
|
const setupPromise = PromiseResolve(setup?.(root.reporter));
|
||||||
|
PromisePrototypeThen(PromisePrototypeThen(PromisePrototypeThen(setupPromise, runFiles), postRun), teardown);
|
||||||
|
|
||||||
return root.reporter;
|
return root.reporter;
|
||||||
}
|
}
|
||||||
|
@ -551,3 +551,13 @@ describe('forceExit', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// exitHandler doesn't run until after the tests / after hooks finish.
|
||||||
|
process.on('exit', () => {
|
||||||
|
assert.strictEqual(process.listeners('uncaughtException').length, 0);
|
||||||
|
assert.strictEqual(process.listeners('unhandledRejection').length, 0);
|
||||||
|
assert.strictEqual(process.listeners('beforeExit').length, 0);
|
||||||
|
assert.strictEqual(process.listeners('SIGINT').length, 0);
|
||||||
|
assert.strictEqual(process.listeners('SIGTERM').length, 0);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user