From 012acb04de00cdcf4dcbbb86a8c50fc27a112dcf Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 2 Aug 2022 08:52:41 +0300 Subject: [PATCH] feat: verbous error when entire test tree is canceled PR-URL: https://github.com/nodejs/node/pull/44060 Reviewed-By: Antoine du Hamel Reviewed-By: Benjamin Gruenbaum (cherry picked from commit 8cf33850bea691d8c53b2d4175c959c8549aa76c) --- lib/internal/test_runner/harness.js | 8 +++++--- lib/internal/test_runner/test.js | 17 ++++------------- test/message/test_runner_no_refs.out | 4 ++-- test/message/test_runner_unresolved_promise.out | 4 ++-- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index 4d6e9c4..987de95 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -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, @@ -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() @@ -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 diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 89b2f35..b4fac63 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -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 @@ -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) { @@ -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 } diff --git a/test/message/test_runner_no_refs.out b/test/message/test_runner_no_refs.out index 63b79cd..e8560c5 100644 --- a/test/message/test_runner_no_refs.out +++ b/test/message/test_runner_no_refs.out @@ -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: |- * @@ -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: |- * diff --git a/test/message/test_runner_unresolved_promise.out b/test/message/test_runner_unresolved_promise.out index 2bb543c..b4d6cba 100644 --- a/test/message/test_runner_unresolved_promise.out +++ b/test/message/test_runner_unresolved_promise.out @@ -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: |- * @@ -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: |- *