Skip to content

Commit bb52656

Browse files
authored
Revert "test_runner: run global after() hook earlier"
This reverts commit 6346bdc. Reason for revert: breaking CI PR-URL: #49110 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent e117f16 commit bb52656

7 files changed

+9
-104
lines changed

lib/internal/test_runner/harness.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ function setup(root) {
142142
const rejectionHandler =
143143
createProcessEventHandler('unhandledRejection', root);
144144
const coverage = configureCoverage(root, globalOptions);
145-
const exitHandler = () => {
146-
root.postRun(new ERR_TEST_FAILURE(
145+
const exitHandler = async () => {
146+
await root.run(new ERR_TEST_FAILURE(
147147
'Promise resolution is still pending but the event loop has already resolved',
148148
kCancelledByParent));
149149

@@ -152,8 +152,8 @@ function setup(root) {
152152
process.removeListener('uncaughtException', exceptionHandler);
153153
};
154154

155-
const terminationHandler = () => {
156-
exitHandler();
155+
const terminationHandler = async () => {
156+
await exitHandler();
157157
process.exit();
158158
};
159159

lib/internal/test_runner/test.js

+4-23
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ class Test extends AsyncResource {
574574
}
575575
}
576576

577-
async run() {
577+
async run(pendingSubtestsError) {
578578
if (this.parent !== null) {
579579
this.parent.activeSubtests++;
580580
}
@@ -662,16 +662,9 @@ class Test extends AsyncResource {
662662
}
663663
}
664664

665-
if (this.parent !== null) {
666-
// Clean up the test. Then, try to report the results and execute any
667-
// tests that were pending due to available concurrency.
668-
//
669-
// The root test is skipped here because it is a special case. Its
670-
// postRun() method is called when the process is getting ready to exit.
671-
// This helps catch any asynchronous activity that occurs after the tests
672-
// have finished executing.
673-
this.postRun();
674-
}
665+
// Clean up the test. Then, try to report the results and execute any
666+
// tests that were pending due to available concurrency.
667+
this.postRun(pendingSubtestsError);
675668
}
676669

677670
postRun(pendingSubtestsError) {
@@ -713,18 +706,6 @@ class Test extends AsyncResource {
713706
this.parent.addReadySubtest(this);
714707
this.parent.processReadySubtestRange(false);
715708
this.parent.processPendingSubtests();
716-
717-
if (this.parent === this.root &&
718-
this.root.activeSubtests === 0 &&
719-
this.root.pendingSubtests.length === 0 &&
720-
this.root.readySubtests.size === 0 &&
721-
this.root.hooks.after.length > 0) {
722-
// This is done so that any global after() hooks are run. At this point
723-
// all of the tests have finished running. However, there might be
724-
// ref'ed handles keeping the event loop alive. This gives the global
725-
// after() hook a chance to clean them up.
726-
this.root.run();
727-
}
728709
} else if (!this.reported) {
729710
const {
730711
diagnostics,

test/fixtures/test-runner/output/async-test-scheduling.mjs

-13
This file was deleted.

test/fixtures/test-runner/output/async-test-scheduling.snapshot

-37
This file was deleted.

test/fixtures/test-runner/output/global_after_should_fail_the_test.snapshot

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ not ok 2 - /test/fixtures/test-runner/output/global_after_should_fail_the_test.j
2222
*
2323
*
2424
*
25+
*
2526
...
2627
1..1
2728
# tests 1

test/parallel/test-runner-output.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const tests = [
7474
{ name: 'test-runner/output/unresolved_promise.js' },
7575
{ name: 'test-runner/output/default_output.js', transform: specTransform, tty: true },
7676
{ name: 'test-runner/output/arbitrary-output.js' },
77-
{ name: 'test-runner/output/async-test-scheduling.mjs' },
7877
!skipForceColors ? {
7978
name: 'test-runner/output/arbitrary-output-colored.js',
8079
transform: snapshot.transform(specTransform, replaceTestDuration), tty: true

test/parallel/test-runner-root-after-with-refed-handles.js

-26
This file was deleted.

0 commit comments

Comments
 (0)