Skip to content

Commit

Permalink
feat: verbous error when entire test tree is canceled
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#44060
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
(cherry picked from commit 8cf33850bea691d8c53b2d4175c959c8549aa76c)
  • Loading branch information
MoLow committed Feb 2, 2023
1 parent 9b04919 commit 012acb0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
8 changes: 5 additions & 3 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/659dc126932f986fc33c7f1c878cb2b57a1e2fac/lib/internal/test_runner/harness.js
// https://github.com/nodejs/node/blob/8cf33850bea691d8c53b2d4175c959c8549aa76c/lib/internal/test_runner/harness.js
'use strict'
const {
ArrayPrototypeForEach,
Expand All @@ -15,7 +15,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 @@ -80,7 +80,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
17 changes: 4 additions & 13 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,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 @@ -530,8 +530,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 @@ -694,13 +694,4 @@ class Suite extends Test {
}
}

module.exports = {
ItTest,
kCancelledByParent,
kDefaultIndent,
kHookFailure,
kSubtestsFailed,
kTestCodeFailure,
Suite,
Test
}
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 012acb0

Please sign in to comment.