Skip to content

Commit

Permalink
test_runner: print failing assertion only once with spec reporter
Browse files Browse the repository at this point in the history
Co-authored-by: Llorx <[email protected]>
PR-URL: #56662
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
2 people authored and jasnell committed Jan 24, 2025
1 parent 01a5aa2 commit c752615
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 782 deletions.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/reporter/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SpecReporter extends Transform {
hasChildren = true;
}
const indentation = indent(data.nesting);
return `${formatTestReport(type, data, prefix, indentation, hasChildren)}\n`;
return `${formatTestReport(type, data, prefix, indentation, hasChildren, false)}\n`;
}
#handleEvent({ type, data }) {
switch (type) {
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/test_runner/reporter/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function formatError(error, indent) {
return `\n${indent} ${message}\n`;
}

function formatTestReport(type, data, prefix = '', indent = '', hasChildren = false) {
function formatTestReport(type, data, prefix = '', indent = '', hasChildren = false, showErrorDetails = true) {
let color = reporterColorMap[type] ?? colors.white;
let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
const { skip, todo } = data;
Expand All @@ -71,10 +71,12 @@ function formatTestReport(type, data, prefix = '', indent = '', hasChildren = fa
} else if (todo !== undefined) {
title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
}
const error = formatError(data.details?.error, indent);

const error = showErrorDetails ? formatError(data.details?.error, indent) : '';
const err = hasChildren ?
(!error || data.details?.error?.failureType === 'subtestsFailed' ? '' : `\n${error}`) :
error;

if (skip !== undefined) {
color = colors.gray;
symbol = reporterUnicodeSymbolMap['hyphen:minus'];
Expand Down
12 changes: 0 additions & 12 deletions test/fixtures/test-runner/output/assertion-color-tty.snapshot
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
[31m✖ failing assertion [90m(*ms)[39m[39m
[AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
[32mactual[39m [31mexpected[39m

[39m'[39m[32m![39m[39mH[39m[39me[39m[39ml[39m[39ml[39m[39mo[39m[39m [39m[39mW[39m[39mo[39m[39mr[39m[39ml[39m[39md[39m[31m![39m[39m'[39m
] {
generatedMessage: [33mtrue[39m,
code: [32m'ERR_ASSERTION'[39m,
actual: [32m'!Hello World'[39m,
expected: [32m'Hello World!'[39m,
operator: [32m'strictEqual'[39m
}

[34mℹ tests 1[39m
[34mℹ suites 0[39m
[34mℹ pass 0[39m
Expand Down
23 changes: 0 additions & 23 deletions test/fixtures/test-runner/output/default_output.snapshot
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
[32m✔ should pass [90m(*ms)[39m[39m
[31m✖ should fail [90m(*ms)[39m[39m
Error: fail
*[39m
*[39m
*[39m
*[39m
*[39m
*[39m
*[39m

[90m﹣ should skip [90m(*ms)[39m # SKIP[39m
▶ parent
[31m✖ should fail [90m(*ms)[39m[39m
Error: fail
*[39m
*[39m
*[39m
*[39m
*[39m
*[39m
*[39m
*[39m
*[39m
*[39m

[31m✖ should pass but parent fail [90m(*ms)[39m[39m
[32m'test did not finish before its parent and was cancelled'[39m

[31m✖ parent [90m(*ms)[39m[39m
[34mℹ tests 6[39m
[34mℹ suites 0[39m
Expand Down
9 changes: 0 additions & 9 deletions test/fixtures/test-runner/output/eval_spec.snapshot
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
✔ passes (*ms)
✖ fails (*ms)
Error: fail
*
*
*
*
*
*
*

ℹ tests 2
ℹ suites 0
ℹ pass 1
Expand Down
Loading

0 comments on commit c752615

Please sign in to comment.