Skip to content

Commit

Permalink
test_runner: fix improper text color reset
Browse files Browse the repository at this point in the history
Upon 'test:fail', text color is not reset correctly
if duration is not printed.
  • Loading branch information
HinataKah0 committed Mar 22, 2023
1 parent 57a35b3 commit c4fd2c7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/reporter/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SpecReporter extends Transform {
color = gray;
symbol = symbols['hyphen:minus'];
}
return `${prefix}${indent}${color}${symbol}${title}${error}${white}`;
return `${prefix}${indent}${color}${symbol}${title}${white}${error}`;
}
#handleTestReportEvent(type, data) {
const subtest = ArrayPrototypeShift(this.#stack); // This is the matching `test:start` event
Expand Down
4 changes: 4 additions & 0 deletions test/pseudo-tty/test_runner_default_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ const test = require('node:test');
test('should pass', () => {});
test('should fail', () => { throw new Error('fail'); });
test('should skip', { skip: true }, () => {});
test('parent', () => {
test('should fail', () => { throw new Error('fail'); });
test('should pass but parent fail', () => {});
});
41 changes: 34 additions & 7 deletions test/pseudo-tty/test_runner_default_reporter.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[32m* should pass [90m(*ms)[39m[39m
[31m* should fail [90m(*ms)[39m
[31m* should fail [90m(*ms)[39m[39m
Error: fail
at * [90m(*)[39m
[90m at *[39m
Expand All @@ -8,20 +8,34 @@
[90m at *[39m
[90m at *[39m
[90m at *[39m
**

[90m* should skip [90m(*ms)[39m # SKIP[39m
[34m* tests 3[39m
* parent
[31m* should fail [90m(*ms)[39m[39m
Error: fail
at * [90m(*)[39m
[90m at *[39m
[90m at *[39m
[90m at *[39m
[90m at *[39m

[31m* should pass but parent fail [90m(*ms)[39m[39m
[32m'test did not finish before its parent and was cancelled'[39m

[31m* [39mparent [90m(*ms)[39m

[34m* tests 6[39m
[34m* suites 0[39m
[34m* pass 1[39m
[34m* fail 1[39m
[34m* cancelled 0[39m
[34m* fail 3[39m
[34m* cancelled 1[39m
[34m* skipped 1[39m
[34m* todo 0[39m
[34m* duration_ms *[39m

[31m* failing tests:[39m

[31m* should fail [90m(*ms)[39m
[31m* should fail [90m(*ms)[39m[39m
Error: fail
at * [90m(*)[39m
[90m at *[39m
Expand All @@ -30,4 +44,17 @@
[90m at *[39m
[90m at *[39m
[90m at *[39m
[39m

[31m* should fail [90m(*ms)[39m[39m
Error: fail
at * [90m(*)[39m
[90m at *[39m
[90m at *[39m
[90m at *[39m
[90m at *[39m

[31m* should pass but parent fail [90m(*ms)[39m[39m
[32m'test did not finish before its parent and was cancelled'[39m

[31m* parent [90m(*ms)[39m[39m
[32m'2 subtests failed'[39m

0 comments on commit c4fd2c7

Please sign in to comment.