Skip to content

Commit fe46cc8

Browse files
committed
test_runner: fix todo and only in spec reporter
1 parent 6cd6789 commit fe46cc8

File tree

6 files changed

+44
-60
lines changed

6 files changed

+44
-60
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 || todo !== 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) {

lib/internal/test_runner/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class Test extends AsyncResource {
259259
skip = '\'only\' option not set';
260260
}
261261

262-
if (skip) {
262+
if (skip || todo) {
263263
fn = noop;
264264
}
265265

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

+5-5
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 be thrown');
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 be thrown');
2222
});
2323

2424
it.skip('sync skip pass', () => {
@@ -44,7 +44,7 @@ it('async pass', async () => {
4444
test('mixing describe/it and test should work', () => {});
4545

4646
it('async throw fail', async () => {
47-
throw new Error('thrown from async throw fail');
47+
throw new Error('should not be thrown');
4848
});
4949

5050
it('async skip fail', async (t, done) => {

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

+5-27
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,15 @@ 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+
ok 3 - sync todo # TODO
1414
---
1515
duration_ms: *
16-
failureType: 'testCodeFailure'
17-
error: 'thrown from sync fail todo'
18-
code: 'ERR_TEST_FAILURE'
19-
stack: |-
20-
*
21-
*
22-
*
23-
*
24-
*
25-
*
26-
*
2716
...
28-
# Subtest: sync fail todo with message
29-
not ok 4 - sync fail todo with message # TODO this is a failing todo
17+
# Subtest: sync todo with message
18+
ok 4 - sync todo with message # TODO this is a failing todo
3019
---
3120
duration_ms: *
32-
failureType: 'testCodeFailure'
33-
error: 'thrown from sync fail todo with message'
34-
code: 'ERR_TEST_FAILURE'
35-
stack: |-
36-
*
37-
*
38-
*
39-
*
40-
*
41-
*
42-
*
4321
...
4422
# Subtest: sync skip pass
4523
ok 5 - sync skip pass # SKIP
@@ -92,7 +70,7 @@ not ok 12 - async throw fail
9270
---
9371
duration_ms: *
9472
failureType: 'testCodeFailure'
95-
error: 'thrown from async throw fail'
73+
error: 'should not be thrown'
9674
code: 'ERR_TEST_FAILURE'
9775
stack: |-
9876
*

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)