Skip to content

Commit e2668c0

Browse files
pmarchiniLlorx
authored andcommitted
test_runner: print failing assertion only once with spec reporter
Co-authored-by: Llorx <dallorx@gmail.com> PR-URL: #56662 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8f59f5b commit e2668c0

File tree

8 files changed

+5
-782
lines changed

8 files changed

+5
-782
lines changed

lib/internal/test_runner/reporter/spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SpecReporter extends Transform {
5252
hasChildren = true;
5353
}
5454
const indentation = indent(data.nesting);
55-
return `${formatTestReport(type, data, prefix, indentation, hasChildren)}\n`;
55+
return `${formatTestReport(type, data, prefix, indentation, hasChildren, false)}\n`;
5656
}
5757
#handleEvent({ type, data }) {
5858
switch (type) {

lib/internal/test_runner/reporter/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function formatError(error, indent) {
5959
return `\n${indent} ${message}\n`;
6060
}
6161

62-
function formatTestReport(type, data, prefix = '', indent = '', hasChildren = false) {
62+
function formatTestReport(type, data, prefix = '', indent = '', hasChildren = false, showErrorDetails = true) {
6363
let color = reporterColorMap[type] ?? colors.white;
6464
let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
6565
const { skip, todo } = data;
@@ -71,10 +71,12 @@ function formatTestReport(type, data, prefix = '', indent = '', hasChildren = fa
7171
} else if (todo !== undefined) {
7272
title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
7373
}
74-
const error = formatError(data.details?.error, indent);
74+
75+
const error = showErrorDetails ? formatError(data.details?.error, indent) : '';
7576
const err = hasChildren ?
7677
(!error || data.details?.error?.failureType === 'subtestsFailed' ? '' : `\n${error}`) :
7778
error;
79+
7880
if (skip !== undefined) {
7981
color = colors.gray;
8082
symbol = reporterUnicodeSymbolMap['hyphen:minus'];

test/fixtures/test-runner/output/assertion-color-tty.snapshot

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
[31m✖ failing assertion [90m(*ms)[39m[39m
2-
[AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
3-
[32mactual[39m [31mexpected[39m
4-
5-
[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
6-
] {
7-
generatedMessage: [33mtrue[39m,
8-
code: [32m'ERR_ASSERTION'[39m,
9-
actual: [32m'!Hello World'[39m,
10-
expected: [32m'Hello World!'[39m,
11-
operator: [32m'strictEqual'[39m
12-
}
13-
142
[34mℹ tests 1[39m
153
[34mℹ suites 0[39m
164
[34mℹ pass 0[39m

test/fixtures/test-runner/output/default_output.snapshot

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
[32m✔ should pass [90m(*ms)[39m[39m
22
[31m✖ should fail [90m(*ms)[39m[39m
3-
Error: fail
4-
*[39m
5-
*[39m
6-
*[39m
7-
*[39m
8-
*[39m
9-
*[39m
10-
*[39m
11-
123
[90m﹣ should skip [90m(*ms)[39m # SKIP[39m
134
▶ parent
145
[31m✖ should fail [90m(*ms)[39m[39m
15-
Error: fail
16-
*[39m
17-
*[39m
18-
*[39m
19-
*[39m
20-
*[39m
21-
*[39m
22-
*[39m
23-
*[39m
24-
*[39m
25-
*[39m
26-
276
[31m✖ should pass but parent fail [90m(*ms)[39m[39m
28-
[32m'test did not finish before its parent and was cancelled'[39m
29-
307
[31m✖ parent [90m(*ms)[39m[39m
318
[34mℹ tests 6[39m
329
[34mℹ suites 0[39m

test/fixtures/test-runner/output/eval_spec.snapshot

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
✔ passes (*ms)
22
✖ fails (*ms)
3-
Error: fail
4-
*
5-
*
6-
*
7-
*
8-
*
9-
*
10-
*
11-
123
ℹ tests 2
134
ℹ suites 0
145
ℹ pass 1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy