Skip to content

Commit c4fd2c7

Browse files
committed
test_runner: fix improper text color reset
Upon 'test:fail', text color is not reset correctly if duration is not printed.
1 parent 57a35b3 commit c4fd2c7

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

lib/internal/test_runner/reporter/spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class SpecReporter extends Transform {
7676
color = gray;
7777
symbol = symbols['hyphen:minus'];
7878
}
79-
return `${prefix}${indent}${color}${symbol}${title}${error}${white}`;
79+
return `${prefix}${indent}${color}${symbol}${title}${white}${error}`;
8080
}
8181
#handleTestReportEvent(type, data) {
8282
const subtest = ArrayPrototypeShift(this.#stack); // This is the matching `test:start` event

test/pseudo-tty/test_runner_default_reporter.js

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ const test = require('node:test');
99
test('should pass', () => {});
1010
test('should fail', () => { throw new Error('fail'); });
1111
test('should skip', { skip: true }, () => {});
12+
test('parent', () => {
13+
test('should fail', () => { throw new Error('fail'); });
14+
test('should pass but parent fail', () => {});
15+
});
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[32m* should pass [90m(*ms)[39m[39m
2-
[31m* should fail [90m(*ms)[39m
2+
[31m* should fail [90m(*ms)[39m[39m
33
Error: fail
44
at * [90m(*)[39m
55
[90m at *[39m
@@ -8,20 +8,34 @@
88
[90m at *[39m
99
[90m at *[39m
1010
[90m at *[39m
11-
**
11+
1212
[90m* should skip [90m(*ms)[39m # SKIP[39m
13-
[34m* tests 3[39m
13+
* parent
14+
[31m* should fail [90m(*ms)[39m[39m
15+
Error: fail
16+
at * [90m(*)[39m
17+
[90m at *[39m
18+
[90m at *[39m
19+
[90m at *[39m
20+
[90m at *[39m
21+
22+
[31m* should pass but parent fail [90m(*ms)[39m[39m
23+
[32m'test did not finish before its parent and was cancelled'[39m
24+
25+
[31m* [39mparent [90m(*ms)[39m
26+
27+
[34m* tests 6[39m
1428
[34m* suites 0[39m
1529
[34m* pass 1[39m
16-
[34m* fail 1[39m
17-
[34m* cancelled 0[39m
30+
[34m* fail 3[39m
31+
[34m* cancelled 1[39m
1832
[34m* skipped 1[39m
1933
[34m* todo 0[39m
2034
[34m* duration_ms *[39m
2135

2236
[31m* failing tests:[39m
2337

24-
[31m* should fail [90m(*ms)[39m
38+
[31m* should fail [90m(*ms)[39m[39m
2539
Error: fail
2640
at * [90m(*)[39m
2741
[90m at *[39m
@@ -30,4 +44,17 @@
3044
[90m at *[39m
3145
[90m at *[39m
3246
[90m at *[39m
33-
[39m
47+
48+
[31m* should fail [90m(*ms)[39m[39m
49+
Error: fail
50+
at * [90m(*)[39m
51+
[90m at *[39m
52+
[90m at *[39m
53+
[90m at *[39m
54+
[90m at *[39m
55+
56+
[31m* should pass but parent fail [90m(*ms)[39m[39m
57+
[32m'test did not finish before its parent and was cancelled'[39m
58+
59+
[31m* parent [90m(*ms)[39m[39m
60+
[32m'2 subtests failed'[39m

0 commit comments

Comments
 (0)