GeezerVison is showing github.com — test_runner: cleanup global event listeners after run · nodejs/node@367f9e7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -170,8 +170,13 @@ function setup(root) { | 170 | 170 | kCancelledByParent)); | 171 | 171 |
| 172 | 172 | hook.disable(); | 173 | | - process.removeListener('unhandledRejection', rejectionHandler); | 174 | 173 | 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 | + } | 175 | 180 | }; | 176 | 181 |
| 177 | 182 | const terminationHandler = () => { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -591,6 +591,7 @@ function run(options) { | 591 | 591 | } | 592 | 592 |
| 593 | 593 | let postRun = () => root.postRun(); | | 594 | + let teardown = () => root.harness.teardown(); | 594 | 595 | let filesWatcher; | 595 | 596 | const opts = { | 596 | 597 | __proto__: null, | @@ -604,6 +605,7 @@ function run(options) { | 604 | 605 | if (watch) { | 605 | 606 | filesWatcher = watchFiles(testFiles, opts); | 606 | 607 | postRun = undefined; | | 608 | + teardown = undefined; | 607 | 609 | } | 608 | 610 | const runFiles = () => { | 609 | 611 | root.harness.bootstrapComplete = true; | @@ -615,7 +617,8 @@ function run(options) { | 615 | 617 | }); | 616 | 618 | }; | 617 | 619 |
| 618 | | - PromisePrototypeThen(PromisePrototypeThen(PromiseResolve(setup?.(root.reporter)), runFiles), postRun); | | 620 | + const setupPromise = PromiseResolve(setup?.(root.reporter)); | | 621 | + PromisePrototypeThen(PromisePrototypeThen(PromisePrototypeThen(setupPromise, runFiles), postRun), teardown); | 619 | 622 |
| 620 | 623 | return root.reporter; | 621 | 624 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-run.mjs +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -542,3 +542,13 @@ describe('forceExit', () => { | 542 | 542 | }); | 543 | 543 | }); | 544 | 544 | }); | | 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 | +}); |
|