Skip to content

Commit e57992f

Browse files
authored
test_runner: hide new line when no error in spec reporter
PR-URL: #52297 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent ac9e5e7 commit e57992f

File tree

6 files changed

+2
-30
lines changed

6 files changed

+2
-30
lines changed

lib/internal/test_runner/reporter/spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class SpecReporter extends Transform {
8383
const error = this.#formatError(data.details?.error, indent);
8484
if (hasChildren) {
8585
// If this test has had children - it was already reported, so slightly modify the output
86-
const err = data.details?.error?.failureType === 'subtestsFailed' ? '' : error;
87-
return `${prefix}${indent}${color}${symbols['arrow:right']}${colors.white}${title}\n${err}`;
86+
const err = !error || data.details?.error?.failureType === 'subtestsFailed' ? '' : `\n${error}`;
87+
return `${prefix}${indent}${color}${symbols['arrow:right']}${colors.white}${title}${err}`;
8888
}
8989
if (skip !== undefined) {
9090
color = colors.gray;

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

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
[32m'test did not finish before its parent and was cancelled'[39m
2929

3030
[31m▶ [39mparent [90m(*ms)[39m
31-
3231
[34mℹ tests 6[39m
3332
[34mℹ suites 0[39m
3433
[34mℹ pass 1[39m

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

-14
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
nested 1 (*ms)
77
nested 2 (*ms)
88
nested (*ms)
9-
109
describe hooks (*ms)
11-
1210
describe hooks - no subtests (*ms)
1311
before throws
1412
1
@@ -96,7 +94,6 @@
9694
*
9795

9896
beforeEach throws (*ms)
99-
10097
afterEach throws
10198
1 (*ms)
10299
Error: afterEach
@@ -124,7 +121,6 @@
124121
*
125122

126123
afterEach throws (*ms)
127-
128124
afterEach when test fails
129125
1 (*ms)
130126
Error: test
@@ -141,7 +137,6 @@
141137

142138
2 (*ms)
143139
afterEach when test fails (*ms)
144-
145140
afterEach throws and test fails
146141
1 (*ms)
147142
Error: test
@@ -169,17 +164,14 @@
169164
*
170165

171166
afterEach throws and test fails (*ms)
172-
173167
test hooks
174168
1 (*ms)
175169
2 (*ms)
176170
nested
177171
nested 1 (*ms)
178172
nested 2 (*ms)
179173
nested (*ms)
180-
181174
test hooks (*ms)
182-
183175
test hooks - no subtests (*ms)
184176
t.before throws
185177
1 (*ms)
@@ -293,7 +285,6 @@
293285
*
294286

295287
t.beforeEach throws (*ms)
296-
297288
t.afterEach throws
298289
1 (*ms)
299290
Error: afterEach
@@ -322,7 +313,6 @@
322313
*
323314

324315
t.afterEach throws (*ms)
325-
326316
afterEach when test fails
327317
1 (*ms)
328318
Error: test
@@ -338,11 +328,9 @@
338328

339329
2 (*ms)
340330
afterEach when test fails (*ms)
341-
342331
afterEach context when test passes
343332
1 (*ms)
344333
afterEach context when test passes (*ms)
345-
346334
afterEach context when test fails
347335
1 (*ms)
348336
Error: test
@@ -352,7 +340,6 @@
352340
*
353341

354342
afterEach context when test fails (*ms)
355-
356343
afterEach throws and test fails
357344
1 (*ms)
358345
Error: test
@@ -380,7 +367,6 @@
380367
*
381368

382369
afterEach throws and test fails (*ms)
383-
384370
t.after() is called if test body throws (*ms)
385371
Error: bye
386372
*

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

-6
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107

108108
this subtest should make its parent test fail
109109
subtest sync throw fail (*ms)
110-
111110
sync throw non-error fail (*ms)
112111
Symbol(thrown symbol from sync throw non-error fail)
113112

@@ -117,17 +116,14 @@
117116
level 1c (*ms)
118117
level 1d (*ms)
119118
level 0a (*ms)
120-
121119
top level
122120
+long running (*ms)
123121
'test did not finish before its parent and was cancelled'
124122

125123
+short running
126124
++short running (*ms)
127125
+short running (*ms)
128-
129126
top level (*ms)
130-
131127
invalid subtest - pass but subtest fails (*ms)
132128
sync skip option (*ms) # SKIP
133129
sync skip option with message (*ms) # this is skipped
@@ -197,7 +193,6 @@
197193
'only' and 'runOnly' require the --test-only command-line option.
198194
running subtest 4 (*ms)
199195
only is set but not in only mode (*ms)
200-
201196
'only' and 'runOnly' require the --test-only command-line option.
202197
custom inspect symbol fail (*ms)
203198
customized
@@ -231,7 +226,6 @@
231226
*
232227

233228
subtest sync throw fails (*ms)
234-
235229
timed out async test (*ms)
236230
'test timed out after *ms'
237231

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

-6
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107

108108
this subtest should make its parent test fail
109109
subtest sync throw fail (*ms)
110-
111110
sync throw non-error fail (*ms)
112111
Symbol(thrown symbol from sync throw non-error fail)
113112

@@ -117,17 +116,14 @@
117116
level 1c (*ms)
118117
level 1d (*ms)
119118
level 0a (*ms)
120-
121119
top level
122120
+long running (*ms)
123121
'test did not finish before its parent and was cancelled'
124122

125123
+short running
126124
++short running (*ms)
127125
+short running (*ms)
128-
129126
top level (*ms)
130-
131127
invalid subtest - pass but subtest fails (*ms)
132128
sync skip option (*ms) # SKIP
133129
sync skip option with message (*ms) # this is skipped
@@ -197,7 +193,6 @@
197193
'only' and 'runOnly' require the --test-only command-line option.
198194
running subtest 4 (*ms)
199195
only is set but not in only mode (*ms)
200-
201196
'only' and 'runOnly' require the --test-only command-line option.
202197
custom inspect symbol fail (*ms)
203198
customized
@@ -231,7 +226,6 @@
231226
*
232227

233228
subtest sync throw fails (*ms)
234-
235229
timed out async test (*ms)
236230
'test timed out after *ms'
237231

test/fixtures/test-runner/output/suite-skip-hooks.snapshot

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ AFTER 2
1313
﹣ should not run (*ms) # SKIP
1414
✔ should run 2 (*ms)
1515
▶ suite runs with mixture of skipped tests (*ms)
16-
1716
ℹ tests 4
1817
ℹ suites 2
1918
ℹ pass 2

0 commit comments

Comments
 (0)