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: unwrap error message in TAP reporter #48942

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions lib/internal/test_runner/reporter/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function jsToYaml(indent, name, value, seen) {
}

if (isErrorObj) {
const { kTestCodeFailure, kUnwrapErrors } = lazyLoadTest();
const { kUnwrapErrors } = lazyLoadTest();
const {
cause,
code,
Expand All @@ -198,15 +198,14 @@ function jsToYaml(indent, name, value, seen) {
errStack = cause?.stack ?? errStack;
errCode = cause?.code ?? errCode;
errName = cause?.name ?? errName;
errMsg = cause?.message ?? errMsg;

if (isAssertionLike(cause)) {
errExpected = cause.expected;
errActual = cause.actual;
errOperator = cause.operator ?? errOperator;
errIsAssertion = true;
}
if (failureType === kTestCodeFailure) {
errMsg = cause?.message ?? errMsg;
}
}

result += jsToYaml(indent, 'error', errMsg, seen);
Expand Down
28 changes: 14 additions & 14 deletions test/fixtures/test-runner/output/hooks.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ not ok 2 - before throws
duration_ms: *
type: 'suite'
failureType: 'hookFailed'
error: 'failed running before hook'
error: 'before'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it looks like these error messages are actually less helpful - these are the actual message from the error objects thrown in the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjihrig and why is there no stack? 😅

Copy link
Member

@atlowChemi atlowChemi Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that just the snapshot behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out lines 61 and 62 (in the TAP reporter, the error is serialized to YAML, not a nice to read error like the spec reporter)

code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down Expand Up @@ -86,7 +86,7 @@ not ok 3 - after throws
duration_ms: *
type: 'suite'
failureType: 'hookFailed'
error: 'failed running after hook'
error: 'after'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand All @@ -105,7 +105,7 @@ not ok 3 - after throws
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running beforeEach hook'
error: 'beforeEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand All @@ -124,7 +124,7 @@ not ok 3 - after throws
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running beforeEach hook'
error: 'beforeEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down Expand Up @@ -153,7 +153,7 @@ not ok 4 - beforeEach throws
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running afterEach hook'
error: 'afterEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand All @@ -172,7 +172,7 @@ not ok 4 - beforeEach throws
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running afterEach hook'
error: 'afterEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down Expand Up @@ -254,7 +254,7 @@ not ok 6 - afterEach when test fails
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running afterEach hook'
error: 'afterEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down Expand Up @@ -315,7 +315,7 @@ ok 8 - test hooks
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running before hook'
error: 'before'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand All @@ -334,7 +334,7 @@ ok 8 - test hooks
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running before hook'
error: 'before'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down Expand Up @@ -362,7 +362,7 @@ not ok 9 - t.before throws
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running beforeEach hook'
error: 'beforeEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand All @@ -381,7 +381,7 @@ not ok 9 - t.before throws
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running beforeEach hook'
error: 'beforeEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down Expand Up @@ -409,7 +409,7 @@ not ok 10 - t.beforeEach throws
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running afterEach hook'
error: 'afterEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand All @@ -428,7 +428,7 @@ not ok 10 - t.beforeEach throws
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running afterEach hook'
error: 'afterEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down Expand Up @@ -506,7 +506,7 @@ not ok 12 - afterEach when test fails
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running afterEach hook'
error: 'afterEach'
code: 'ERR_TEST_FAILURE'
stack: |-
*
Expand Down