Skip to content

Commit

Permalink
test_runner: fix reconstruction of errors extracted from YAML
Browse files Browse the repository at this point in the history
PR-URL: #46872
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Nitzan Uziely <linkgoron@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
MoLow authored and targos committed Mar 13, 2023
1 parent 1674601 commit 63cab16
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/internal/test_runner/reporter/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ function jsToYaml(indent, name, value) {
actual,
operator,
stack,
name,
} = value;
let errMsg = message ?? '<unknown error>';
let errName = name;
let errStack = stack;
let errCode = code;
let errExpected = expected;
Expand All @@ -209,6 +211,7 @@ function jsToYaml(indent, name, value) {
if (code === 'ERR_TEST_FAILURE' && kUnwrapErrors.has(failureType)) {
errStack = cause?.stack ?? errStack;
errCode = cause?.code ?? errCode;
errName = cause?.name ?? errName;
if (isAssertionLike(cause)) {
errExpected = cause.expected;
errActual = cause.actual;
Expand All @@ -225,6 +228,9 @@ function jsToYaml(indent, name, value) {
if (errCode) {
result += jsToYaml(indent, 'code', errCode);
}
if (errName && errName !== 'Error') {
result += jsToYaml(indent, 'name', errName);
}

if (errIsAssertion) {
result += jsToYaml(indent, 'expected', errExpected);
Expand Down
6 changes: 5 additions & 1 deletion lib/internal/test_runner/yaml_to_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ function reConstructError(parsedYaml) {
} else {
// eslint-disable-next-line no-restricted-syntax
cause = new Error(parsedYaml.error);
}
const name = parsedYaml.name ?? 'Error';
cause.stack = `${name}: ${parsedYaml.error}\n${stack}`;

if (!isAssertionError && !isTestFailure) {
cause.code = parsedYaml.code;
}
cause.stack = stack;

if (isTestFailure) {
error = new ERR_TEST_FAILURE(cause, parsedYaml.failureType);
Expand Down
10 changes: 10 additions & 0 deletions test/message/test_runner_abort.out
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ TAP version 13
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand All @@ -62,6 +63,7 @@ TAP version 13
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand All @@ -81,6 +83,7 @@ TAP version 13
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand All @@ -100,6 +103,7 @@ not ok 1 - promise timeout signal
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
name: 'TimeoutError'
stack: |-
*
*
Expand All @@ -113,6 +117,7 @@ not ok 2 - promise abort signal
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand Down Expand Up @@ -168,6 +173,7 @@ not ok 2 - promise abort signal
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand All @@ -187,6 +193,7 @@ not ok 2 - promise abort signal
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand All @@ -206,6 +213,7 @@ not ok 2 - promise abort signal
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand All @@ -225,6 +233,7 @@ not ok 3 - callback timeout signal
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
name: 'TimeoutError'
stack: |-
*
*
Expand All @@ -238,6 +247,7 @@ not ok 4 - callback abort signal
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand Down
2 changes: 2 additions & 0 deletions test/message/test_runner_abort_suite.out
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ not ok 1 - describe timeout signal
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
name: 'TimeoutError'
stack: |-
*
*
Expand All @@ -80,6 +81,7 @@ not ok 2 - describe abort signal
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
Expand Down
1 change: 1 addition & 0 deletions test/message/test_runner_describe_it.out
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ not ok 14 - async assertion fail
true !== false

code: 'ERR_ASSERTION'
name: 'AssertionError'
expected: false
actual: true
operator: 'strictEqual'
Expand Down
1 change: 1 addition & 0 deletions test/message/test_runner_output.out
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ not ok 13 - async assertion fail
true !== false

code: 'ERR_ASSERTION'
name: 'AssertionError'
expected: false
actual: true
operator: 'strictEqual'
Expand Down
1 change: 1 addition & 0 deletions test/message/test_runner_output_cli.out
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ not ok 13 - async assertion fail
true !== false

code: 'ERR_ASSERTION'
name: 'AssertionError'
expected: false
actual: true
operator: 'strictEqual'
Expand Down

0 comments on commit 63cab16

Please sign in to comment.