Skip to content

Commit

Permalink
test_runner: verbous error when entire test tree is canceled
Browse files Browse the repository at this point in the history
PR-URL: nodejs#44060
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
MoLow authored and Fyko committed Sep 15, 2022
1 parent 4bf8a97 commit c9af0a4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
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

0 comments on commit c9af0a4

Please sign in to comment.