Skip to content

Commit 1bebcb8

Browse files
committed
test_runner: verbous error when entire test tree is canceled
1 parent 659dc12 commit 1bebcb8

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

lib/internal/test_runner/harness.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
},
1515
} = require('internal/errors');
1616
const { getOptionValue } = require('internal/options');
17-
const { Test, ItTest, Suite } = require('internal/test_runner/test');
17+
const { kCancelledByParent, Test, ItTest, Suite } = require('internal/test_runner/test');
1818

1919
const isTestRunner = getOptionValue('--test');
2020
const testResources = new SafeMap();
@@ -77,7 +77,9 @@ function setup(root) {
7777
createProcessEventHandler('unhandledRejection', root);
7878

7979
const exitHandler = () => {
80-
root.postRun();
80+
const msg = 'There is no more asynchronous activity queued in the event loop, ' +
81+
'thus the test runner has completed and canceled all outstanding pending tests';
82+
root.postRun(new ERR_TEST_FAILURE(msg, kCancelledByParent));
8183

8284
let passCount = 0;
8385
let failCount = 0;

lib/internal/test_runner/test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class Test extends AsyncResource {
511511
this.postRun();
512512
}
513513

514-
postRun() {
514+
postRun(pendingSubtestsError) {
515515
let failedSubtests = 0;
516516

517517
// If the test was failed before it even started, then the end time will
@@ -523,12 +523,13 @@ class Test extends AsyncResource {
523523

524524
// The test has run, so recursively cancel any outstanding subtests and
525525
// mark this test as failed if any subtests failed.
526+
this.pendingSubtests = [];
526527
for (let i = 0; i < this.subtests.length; i++) {
527528
const subtest = this.subtests[i];
528529

529530
if (!subtest.finished) {
530-
subtest.cancel();
531-
subtest.postRun();
531+
subtest.cancel(pendingSubtestsError);
532+
subtest.postRun(pendingSubtestsError);
532533
}
533534

534535
if (!subtest.passed) {
@@ -690,4 +691,4 @@ class Suite extends Test {
690691
}
691692
}
692693

693-
module.exports = { kDefaultIndent, kSubtestsFailed, kTestCodeFailure, Test, Suite, ItTest };
694+
module.exports = { kCancelledByParent, kDefaultIndent, kSubtestsFailed, kTestCodeFailure, Test, Suite, ItTest };

test/message/test_runner_no_refs.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ TAP version 13
55
---
66
duration_ms: *
77
failureType: 'cancelledByParent'
8-
error: 'test did not finish before its parent and was cancelled'
8+
error: 'There is no more asynchronous activity queued in the event loop, thus the test runner has completed and canceled all outstanding pending tests'
99
code: 'ERR_TEST_FAILURE'
1010
stack: |-
1111
*
@@ -15,7 +15,7 @@ not ok 1 - does not keep event loop alive
1515
---
1616
duration_ms: *
1717
failureType: 'cancelledByParent'
18-
error: 'test did not finish before its parent and was cancelled'
18+
error: 'There is no more asynchronous activity queued in the event loop, thus the test runner has completed and canceled all outstanding pending tests'
1919
code: 'ERR_TEST_FAILURE'
2020
stack: |-
2121
*

test/message/test_runner_unresolved_promise.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ const test = require('node:test');
55

66
test('pass');
77
test('never resolving promise', () => new Promise(() => {}));
8-
test('fail');
8+
test('fail', () => console.log('this should not appear'));

test/message/test_runner_unresolved_promise.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ not ok 2 - never resolving promise
99
---
1010
duration_ms: *
1111
failureType: 'cancelledByParent'
12-
error: 'test did not finish before its parent and was cancelled'
12+
error: 'There is no more asynchronous activity queued in the event loop, thus the test runner has completed and canceled all outstanding pending tests'
1313
code: 'ERR_TEST_FAILURE'
1414
stack: |-
1515
*
@@ -19,7 +19,7 @@ not ok 3 - fail
1919
---
2020
duration_ms: *
2121
failureType: 'cancelledByParent'
22-
error: 'test did not finish before its parent and was cancelled'
22+
error: 'There is no more asynchronous activity queued in the event loop, thus the test runner has completed and canceled all outstanding pending tests'
2323
code: 'ERR_TEST_FAILURE'
2424
stack: |-
2525
*

0 commit comments

Comments
 (0)