Skip to content

Commit fe7e936

Browse files
MoLowguangwong
authored andcommitted
test_runner: verbous error when entire test tree is canceled
PR-URL: nodejs/node#44060 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent f308f71 commit fe7e936

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
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+
root.postRun(new ERR_TEST_FAILURE(
81+
'Promise resolution is still pending but the event loop has already resolved',
82+
kCancelledByParent));
8183

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

lib/internal/test_runner/test.js

+4-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
@@ -528,8 +528,8 @@ class Test extends AsyncResource {
528528
const subtest = this.subtests[i];
529529

530530
if (!subtest.finished) {
531-
subtest.cancel();
532-
subtest.postRun();
531+
subtest.cancel(pendingSubtestsError);
532+
subtest.postRun(pendingSubtestsError);
533533
}
534534

535535
if (!subtest.passed) {
@@ -691,4 +691,4 @@ class Suite extends Test {
691691
}
692692
}
693693

694-
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: 'Promise resolution is still pending but the event loop has already resolved'
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: 'Promise resolution is still pending but the event loop has already resolved'
1919
code: 'ERR_TEST_FAILURE'
2020
stack: |-
2121
*

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: 'Promise resolution is still pending but the event loop has already resolved'
1313
code: 'ERR_TEST_FAILURE'
1414
stack: |-
1515
*
@@ -19,7 +19,7 @@ not ok 3 - fail
1919
---
2020
duration_ms: 0
2121
failureType: 'cancelledByParent'
22-
error: 'test did not finish before its parent and was cancelled'
22+
error: 'Promise resolution is still pending but the event loop has already resolved'
2323
code: 'ERR_TEST_FAILURE'
2424
stack: |-
2525
*

0 commit comments

Comments
 (0)