Skip to content

Commit 0b7bf9a

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 63b1965 commit 0b7bf9a

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

lib/internal/test_runner/reporter/spec.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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+
});
Lines changed: 33 additions & 6 deletions
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,19 +8,33 @@
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 4[39m
1428
[34m* pass 1[39m
15-
[34m* fail 1[39m
29+
[34m* fail 2[39m
1630
[34m* cancelled 0[39m
1731
[34m* skipped 1[39m
1832
[34m* todo 0[39m
1933
[34m* duration_ms *[39m
2034

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

23-
[31m* should fail [90m(*ms)[39m
37+
[31m* should fail [90m(*ms)[39m[39m
2438
Error: fail
2539
at * [90m(*)[39m
2640
[90m at *[39m
@@ -29,4 +43,17 @@
2943
[90m at *[39m
3044
[90m at *[39m
3145
[90m at *[39m
32-
[39m
46+
47+
[31m* should fail [90m(*ms)[39m[39m
48+
Error: fail
49+
at * [90m(*)[39m
50+
[90m at *[39m
51+
[90m at *[39m
52+
[90m at *[39m
53+
[90m at *[39m
54+
55+
[31m✖ should pass but parent fail [90m(*ms)[39m[39m
56+
[32m'test did not finish before its parent and was cancelled'[39m
57+
58+
[31m* parent [90m(*ms)[39m[39m
59+
[32m'2 subtests failed'[39m

0 commit comments

Comments
 (0)