From 9b04919c3a75de5502797bedd2b784664cbb71c9 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Mon, 22 Aug 2022 09:36:46 +0300 Subject: [PATCH] Pull latest changes from nodejs/node (#40) --- lib/internal/test_runner/tap_stream.js | 10 +-- lib/internal/test_runner/test.js | 13 +++- test/message/test_runner_hooks.out | 96 ++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 6 deletions(-) diff --git a/lib/internal/test_runner/tap_stream.js b/lib/internal/test_runner/tap_stream.js index 663f79b..e240598 100644 --- a/lib/internal/test_runner/tap_stream.js +++ b/lib/internal/test_runner/tap_stream.js @@ -1,4 +1,4 @@ -// https://github.com/nodejs/node/blob/5fadc389b8a9a32809adda8245ad32928623409b/lib/internal/test_runner/tap_stream.js +// https://github.com/nodejs/node/blob/0d46cf6af8977d1e2e4c4886bf0f7e0dbe76d21c/lib/internal/test_runner/tap_stream.js 'use strict' @@ -171,7 +171,7 @@ function jsToYaml (indent, name, value) { } if (isErrorObj) { - const { kTestCodeFailure } = lazyLoadTest() + const { kTestCodeFailure, kHookFailure } = lazyLoadTest() const { cause, code, @@ -185,10 +185,12 @@ function jsToYaml (indent, name, value) { // If the ERR_TEST_FAILURE came from an error provided by user code, // then try to unwrap the original error message and stack. - if (code === 'ERR_TEST_FAILURE' && failureType === kTestCodeFailure) { - errMsg = cause?.message ?? errMsg + if (code === 'ERR_TEST_FAILURE' && (failureType === kTestCodeFailure || failureType === kHookFailure)) { errStack = cause?.stack ?? errStack errCode = cause?.code ?? errCode + if (failureType === kTestCodeFailure) { + errMsg = cause?.message ?? errMsg + } } result += jsToYaml(indent, 'error', errMsg) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index d326fef..89b2f35 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -1,4 +1,4 @@ -// https://github.com/nodejs/node/blob/5e1873e91d8ccefc5576912c24795d229455166d/lib/internal/test_runner/test.js +// https://github.com/nodejs/node/blob/0d46cf6af8977d1e2e4c4886bf0f7e0dbe76d21c/lib/internal/test_runner/test.js 'use strict' @@ -694,4 +694,13 @@ class Suite extends Test { } } -module.exports = { kDefaultIndent, kSubtestsFailed, kTestCodeFailure, Test, Suite, ItTest } +module.exports = { + ItTest, + kCancelledByParent, + kDefaultIndent, + kHookFailure, + kSubtestsFailed, + kTestCodeFailure, + Suite, + Test +} diff --git a/test/message/test_runner_hooks.out b/test/message/test_runner_hooks.out index cd85fe9..57008a4 100644 --- a/test/message/test_runner_hooks.out +++ b/test/message/test_runner_hooks.out @@ -55,6 +55,16 @@ not ok 2 - before throws failureType: 'hookFailed' error: 'failed running before hook' code: 'ERR_TEST_FAILURE' + stack: |- + * + * + * + * + * + * + * + * + * ... # Subtest: after throws # Subtest: 1 @@ -74,6 +84,16 @@ not ok 3 - after throws failureType: 'hookFailed' error: 'failed running after hook' code: 'ERR_TEST_FAILURE' + stack: |- + * + * + * + * + * + * + * + * + * ... # Subtest: beforeEach throws # Subtest: 1 @@ -85,6 +105,15 @@ not ok 3 - after throws code: 'ERR_TEST_FAILURE' stack: |- * + * + * + * + * + * + * + * + * + * ... # Subtest: 2 not ok 2 - 2 @@ -93,6 +122,17 @@ not ok 3 - after throws failureType: 'hookFailed' error: 'failed running beforeEach hook' code: 'ERR_TEST_FAILURE' + stack: |- + * + * + * + * + * + * + * + * + * + * ... 1..2 not ok 4 - beforeEach throws @@ -112,6 +152,15 @@ not ok 4 - beforeEach throws code: 'ERR_TEST_FAILURE' stack: |- * + * + * + * + * + * + * + * + * + * ... # Subtest: 2 not ok 2 - 2 @@ -120,6 +169,17 @@ not ok 4 - beforeEach throws failureType: 'hookFailed' error: 'failed running afterEach hook' code: 'ERR_TEST_FAILURE' + stack: |- + * + * + * + * + * + * + * + * + * + * ... 1..2 not ok 5 - afterEach throws @@ -171,6 +231,15 @@ ok 6 - test hooks code: 'ERR_TEST_FAILURE' stack: |- * + * + * + * + * + * + * + * + * + * ... # Subtest: 2 not ok 2 - 2 @@ -181,6 +250,15 @@ ok 6 - test hooks code: 'ERR_TEST_FAILURE' stack: |- * + * + * + * + * + * + * + * + * + * ... 1..2 not ok 7 - t.beforeEach throws @@ -200,6 +278,15 @@ not ok 7 - t.beforeEach throws code: 'ERR_TEST_FAILURE' stack: |- * + * + * + * + * + * + * + * + * + * ... # Subtest: 2 not ok 2 - 2 @@ -210,6 +297,15 @@ not ok 7 - t.beforeEach throws code: 'ERR_TEST_FAILURE' stack: |- * + * + * + * + * + * + * + * + * + * ... 1..2 not ok 8 - t.afterEach throws