Skip to content

Commit d217435

Browse files
MoLowtargos
authored andcommitted
test_runner: fix todo and only in spec reporter
PR-URL: #48929 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 9f122be commit d217435

File tree

5 files changed

+43
-37
lines changed

5 files changed

+43
-37
lines changed

lib/internal/test_runner/reporter/spec.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,24 @@ class SpecReporter extends Transform {
6464
), `\n${indent} `);
6565
return `\n${indent} ${message}\n`;
6666
}
67-
#formatTestReport(type, data, prefix = '', indent = '', hasChildren = false, skippedSubtest = false) {
67+
#formatTestReport(type, data, prefix = '', indent = '', hasChildren = false) {
6868
let color = colors[type] ?? white;
6969
let symbol = symbols[type] ?? ' ';
70+
const { skip, todo } = data;
7071
const duration_ms = data.details?.duration_ms ? ` ${gray}(${data.details.duration_ms}ms)${white}` : '';
71-
const title = `${data.name}${duration_ms}${skippedSubtest ? ' # SKIP' : ''}`;
72+
let title = `${data.name}${duration_ms}`;
73+
74+
if (skip !== undefined) {
75+
title += ` # ${typeof skip === 'string' && skip.length ? skip : 'SKIP'}`;
76+
} else if (todo !== undefined) {
77+
title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
78+
}
7279
if (hasChildren) {
7380
// If this test has had children - it was already reported, so slightly modify the output
7481
return `${prefix}${indent}${color}${symbols['arrow:right']}${white}${title}\n`;
7582
}
7683
const error = this.#formatError(data.details?.error, indent);
77-
if (skippedSubtest) {
84+
if (skip !== undefined) {
7885
color = gray;
7986
symbol = symbols['hyphen:minus'];
8087
}
@@ -101,9 +108,8 @@ class SpecReporter extends Transform {
101108
ArrayPrototypeShift(this.#reported);
102109
hasChildren = true;
103110
}
104-
const skippedSubtest = subtest && data.skip && data.skip !== undefined;
105111
const indent = this.#indent(data.nesting);
106-
return `${this.#formatTestReport(type, data, prefix, indent, hasChildren, skippedSubtest)}\n`;
112+
return `${this.#formatTestReport(type, data, prefix, indent, hasChildren)}\n`;
107113
}
108114
#handleEvent({ type, data }) {
109115
switch (type) {

test/fixtures/test-runner/output/describe_it.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ it.todo('sync pass todo', () => {
1313
it('sync pass todo with message', { todo: 'this is a passing todo' }, () => {
1414
});
1515

16-
it.todo('sync fail todo', () => {
17-
throw new Error('thrown from sync fail todo');
16+
it.todo('sync todo', () => {
17+
throw new Error('should not count as a failure');
1818
});
1919

20-
it('sync fail todo with message', { todo: 'this is a failing todo' }, () => {
21-
throw new Error('thrown from sync fail todo with message');
20+
it('sync todo with message', { todo: 'this is a failing todo' }, () => {
21+
throw new Error('should not count as a failure');
2222
});
2323

2424
it.skip('sync skip pass', () => {

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ ok 2 - sync pass todo with message # TODO this is a passing todo
99
---
1010
duration_ms: *
1111
...
12-
# Subtest: sync fail todo
13-
not ok 3 - sync fail todo # TODO
12+
# Subtest: sync todo
13+
not ok 3 - sync todo # TODO
1414
---
1515
duration_ms: *
1616
failureType: 'testCodeFailure'
17-
error: 'thrown from sync fail todo'
17+
error: 'should not count as a failure'
1818
code: 'ERR_TEST_FAILURE'
1919
stack: |-
2020
*
@@ -25,12 +25,12 @@ not ok 3 - sync fail todo # TODO
2525
*
2626
*
2727
...
28-
# Subtest: sync fail todo with message
29-
not ok 4 - sync fail todo with message # TODO this is a failing todo
28+
# Subtest: sync todo with message
29+
not ok 4 - sync todo with message # TODO this is a failing todo
3030
---
3131
duration_ms: *
3232
failureType: 'testCodeFailure'
33-
error: 'thrown from sync fail todo with message'
33+
error: 'should not count as a failure'
3434
code: 'ERR_TEST_FAILURE'
3535
stack: |-
3636
*

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
sync pass todo (*ms)
2-
sync pass todo with message (*ms)
3-
sync fail todo (*ms)
1+
sync pass todo (*ms) # TODO
2+
sync pass todo with message (*ms) # this is a passing todo
3+
sync fail todo (*ms) # TODO
44
Error: thrown from sync fail todo
55
*
66
*
@@ -10,7 +10,7 @@
1010
*
1111
*
1212

13-
sync fail todo with message (*ms)
13+
sync fail todo with message (*ms) # this is a failing todo
1414
Error: thrown from sync fail todo with message
1515
*
1616
*
@@ -21,7 +21,7 @@
2121
*
2222

2323
sync skip pass (*ms) # SKIP
24-
sync skip pass with message (*ms) # SKIP
24+
sync skip pass with message (*ms) # this is skipped
2525
sync pass (*ms)
2626
this test should pass
2727
sync throw fail (*ms)
@@ -130,7 +130,7 @@
130130

131131
invalid subtest - pass but subtest fails (*ms)
132132
sync skip option (*ms) # SKIP
133-
sync skip option with message (*ms) # SKIP
133+
sync skip option with message (*ms) # this is skipped
134134
sync skip option is false fail (*ms)
135135
Error: this should be executed
136136
*
@@ -151,8 +151,8 @@
151151
functionAndOptions (*ms) # SKIP
152152
escaped description \ # \#\
153153
 (*ms)
154-
escaped skip message (*ms) # SKIP
155-
escaped todo message (*ms)
154+
escaped skip message (*ms) # #skip
155+
escaped todo message (*ms) # #todo
156156
escaped diagnostic (*ms)
157157
#diagnostic
158158
callback pass (*ms)
@@ -307,7 +307,7 @@
307307

308308
failing tests:
309309

310-
sync fail todo (*ms)
310+
sync fail todo (*ms) # TODO
311311
Error: thrown from sync fail todo
312312
*
313313
*
@@ -317,7 +317,7 @@
317317
*
318318
*
319319

320-
sync fail todo with message (*ms)
320+
sync fail todo with message (*ms) # this is a failing todo
321321
Error: thrown from sync fail todo with message
322322
*
323323
*
@@ -347,7 +347,7 @@
347347
*
348348
*
349349

350-
async skip fail (*ms)
350+
async skip fail (*ms) # SKIP
351351
Error: thrown from async throw fail
352352
*
353353
*

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
sync pass todo (*ms)
2-
sync pass todo with message (*ms)
3-
sync fail todo (*ms)
1+
sync pass todo (*ms) # TODO
2+
sync pass todo with message (*ms) # this is a passing todo
3+
sync fail todo (*ms) # TODO
44
Error: thrown from sync fail todo
55
*
66
*
@@ -10,7 +10,7 @@
1010
*
1111
*
1212

13-
sync fail todo with message (*ms)
13+
sync fail todo with message (*ms) # this is a failing todo
1414
Error: thrown from sync fail todo with message
1515
*
1616
*
@@ -21,7 +21,7 @@
2121
*
2222

2323
sync skip pass (*ms) # SKIP
24-
sync skip pass with message (*ms) # SKIP
24+
sync skip pass with message (*ms) # this is skipped
2525
sync pass (*ms)
2626
this test should pass
2727
sync throw fail (*ms)
@@ -130,7 +130,7 @@
130130

131131
invalid subtest - pass but subtest fails (*ms)
132132
sync skip option (*ms) # SKIP
133-
sync skip option with message (*ms) # SKIP
133+
sync skip option with message (*ms) # this is skipped
134134
sync skip option is false fail (*ms)
135135
Error: this should be executed
136136
*
@@ -151,8 +151,8 @@
151151
functionAndOptions (*ms) # SKIP
152152
escaped description \ # \#\
153153
 (*ms)
154-
escaped skip message (*ms) # SKIP
155-
escaped todo message (*ms)
154+
escaped skip message (*ms) # #skip
155+
escaped todo message (*ms) # #todo
156156
escaped diagnostic (*ms)
157157
#diagnostic
158158
callback pass (*ms)
@@ -307,7 +307,7 @@
307307

308308
failing tests:
309309

310-
sync fail todo (*ms)
310+
sync fail todo (*ms) # TODO
311311
Error: thrown from sync fail todo
312312
*
313313
*
@@ -317,7 +317,7 @@
317317
*
318318
*
319319

320-
sync fail todo with message (*ms)
320+
sync fail todo with message (*ms) # this is a failing todo
321321
Error: thrown from sync fail todo with message
322322
*
323323
*
@@ -347,7 +347,7 @@
347347
*
348348
*
349349

350-
async skip fail (*ms)
350+
async skip fail (*ms) # SKIP
351351
Error: thrown from async throw fail
352352
*
353353
*

0 commit comments

Comments
 (0)