Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: verbose error when entire test tree is canceled #44060

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
},
} = require('internal/errors');
const { getOptionValue } = require('internal/options');
const { Test, ItTest, Suite } = require('internal/test_runner/test');
const { kCancelledByParent, Test, ItTest, Suite } = require('internal/test_runner/test');

const isTestRunner = getOptionValue('--test');
const testResources = new SafeMap();
Expand Down Expand Up @@ -77,7 +77,9 @@ function setup(root) {
createProcessEventHandler('unhandledRejection', root);

const exitHandler = () => {
root.postRun();
root.postRun(new ERR_TEST_FAILURE(
'Promise resolution is still pending but the event loop has already resolved',
kCancelledByParent));

let passCount = 0;
let failCount = 0;
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ class Test extends AsyncResource {
this.postRun();
}

postRun() {
postRun(pendingSubtestsError) {
let failedSubtests = 0;

// If the test was failed before it even started, then the end time will
Expand All @@ -528,8 +528,8 @@ class Test extends AsyncResource {
const subtest = this.subtests[i];

if (!subtest.finished) {
subtest.cancel();
subtest.postRun();
subtest.cancel(pendingSubtestsError);
subtest.postRun(pendingSubtestsError);
}

if (!subtest.passed) {
Expand Down Expand Up @@ -691,4 +691,4 @@ class Suite extends Test {
}
}

module.exports = { kDefaultIndent, kSubtestsFailed, kTestCodeFailure, Test, Suite, ItTest };
module.exports = { kCancelledByParent, kDefaultIndent, kSubtestsFailed, kTestCodeFailure, Test, Suite, ItTest };
4 changes: 2 additions & 2 deletions test/message/test_runner_no_refs.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TAP version 13
---
duration_ms: *
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
error: 'Promise resolution is still pending but the event loop has already resolved'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand All @@ -15,7 +15,7 @@ not ok 1 - does not keep event loop alive
---
duration_ms: *
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
error: 'Promise resolution is still pending but the event loop has already resolved'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down
4 changes: 2 additions & 2 deletions test/message/test_runner_unresolved_promise.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ not ok 2 - never resolving promise
---
duration_ms: *
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
error: 'Promise resolution is still pending but the event loop has already resolved'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand All @@ -19,7 +19,7 @@ not ok 3 - fail
---
duration_ms: 0
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
error: 'Promise resolution is still pending but the event loop has already resolved'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down