Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: fix reconstruction of errors extracted from YAML #46872

Merged
merged 3 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion lib/internal/test_runner/yaml_to_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ function reConstructError(parsedYaml) {
cause = new Error(parsedYaml.error);
cause.code = parsedYaml.code;
MoLow marked this conversation as resolved.
Show resolved Hide resolved
}
cause.stack = stack;
const name = parsedYaml.name ?? 'Error';
cause.stack = `${name}: ${parsedYaml.error}\n${stack}`;

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

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