test_runner: fix test runner hooks failure stack

PR-URL: https://github.com/nodejs/node/pull/44284
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Moshe Atlow authored and Ruy Adorno committed 2022-08-22 19:37:29 -04:00
1 parent a93371205b
commit c0b160c842
3 files changed
+111 -4

No files matched your search

+5 -3
View File
@@ -167,7 +167,7 @@ function jsToYaml(indent, name, value) {
}
if (isErrorObj) {
const { kTestCodeFailure } = lazyLoadTest();
const { kTestCodeFailure, kHookFailure } = lazyLoadTest();
const {
cause,
code,
@@ -181,10 +181,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);
+10 -1
View File
@@ -691,4 +691,13 @@ class Suite extends Test {
}
}
module.exports = { kCancelledByParent, kDefaultIndent, kSubtestsFailed, kTestCodeFailure, Test, Suite, ItTest };
module.exports = {
ItTest,
kCancelledByParent,
kDefaultIndent,
kHookFailure,
kSubtestsFailed,
kTestCodeFailure,
Suite,
Test,
};
+96
View File
@@ -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