Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit367f9e7

Browse files
EddieAbbondanziomarco-ippolito
authored andcommitted
test_runner: cleanup global event listeners after run
PR-URL:#53878Fixes:#53868Reviewed-By: Matteo Collina <matteo.collina@gmail.com>Reviewed-By: James M Snell <jasnell@gmail.com>Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent2e69e5f commit367f9e7

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

‎lib/internal/test_runner/harness.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,13 @@ function setup(root) {
170170
kCancelledByParent));
171171

172172
hook.disable();
173-
process.removeListener('unhandledRejection',rejectionHandler);
174173
process.removeListener('uncaughtException',exceptionHandler);
174+
process.removeListener('unhandledRejection',rejectionHandler);
175+
process.removeListener('beforeExit',exitHandler);
176+
if(globalOptions.isTestRunner){
177+
process.removeListener('SIGINT',terminationHandler);
178+
process.removeListener('SIGTERM',terminationHandler);
179+
}
175180
};
176181

177182
constterminationHandler=()=>{

‎lib/internal/test_runner/runner.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ function run(options) {
591591
}
592592

593593
letpostRun=()=>root.postRun();
594+
letteardown=()=>root.harness.teardown();
594595
letfilesWatcher;
595596
constopts={
596597
__proto__:null,
@@ -604,6 +605,7 @@ function run(options) {
604605
if(watch){
605606
filesWatcher=watchFiles(testFiles,opts);
606607
postRun=undefined;
608+
teardown=undefined;
607609
}
608610
construnFiles=()=>{
609611
root.harness.bootstrapComplete=true;
@@ -615,7 +617,8 @@ function run(options) {
615617
});
616618
};
617619

618-
PromisePrototypeThen(PromisePrototypeThen(PromiseResolve(setup?.(root.reporter)),runFiles),postRun);
620+
constsetupPromise=PromiseResolve(setup?.(root.reporter));
621+
PromisePrototypeThen(PromisePrototypeThen(PromisePrototypeThen(setupPromise,runFiles),postRun),teardown);
619622

620623
returnroot.reporter;
621624
}

‎test/parallel/test-runner-run.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,13 @@ describe('forceExit', () => {
542542
});
543543
});
544544
});
545+
546+
547+
// exitHandler doesn't run until after the tests / after hooks finish.
548+
process.on('exit',()=>{
549+
assert.strictEqual(process.listeners('uncaughtException').length,0);
550+
assert.strictEqual(process.listeners('unhandledRejection').length,0);
551+
assert.strictEqual(process.listeners('beforeExit').length,0);
552+
assert.strictEqual(process.listeners('SIGINT').length,0);
553+
assert.strictEqual(process.listeners('SIGTERM').length,0);
554+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp