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 63b1965 commit 0b7bf9a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/reporter/spec.js
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
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', () => {});
});
39 changes: 33 additions & 6 deletions test/pseudo-tty/test_runner_default_reporter.out
@@ -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,19 +8,33 @@
[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 4[39m
[34m* pass 1[39m
[34m* fail 1[39m
[34m* fail 2[39m
[34m* cancelled 0[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 @@ -29,4 +43,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 0b7bf9a

Please sign in to comment.