Skip to content

Commit 8bcec34

Browse files
committed
test_runner: default to spec reporter when on TTY environment
1 parent ca033c1 commit 8bcec34

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

doc/api/test.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,7 @@ flags for the test runner to use a specific reporter.
520520
The following built-reporters are supported:
521521

522522
* `tap`
523-
The `tap` reporter is the default reporter used by the test runner. It outputs
524-
the test results in the [TAP][] format.
523+
The `tap` reporter outputs the test results in the [TAP][] format.
525524

526525
* `spec`
527526
The `spec` reporter outputs the test results in a human-readable format.
@@ -531,6 +530,9 @@ The following built-reporters are supported:
531530
where each passing test is represented by a `.`,
532531
and each failing test is represented by a `X`.
533532

533+
When `stdout` is a [TTY][], the `spec` reporter is used by default.
534+
Otherwise, the `tap` reporter is used by default.
535+
534536
### Custom reporters
535537

536538
[`--test-reporter`][] can be used to specify a path to custom reporter.
@@ -1768,6 +1770,7 @@ added:
17681770
aborted.
17691771

17701772
[TAP]: https://testanything.org/
1773+
[TTY]: tty.md
17711774
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
17721775
[`--import`]: cli.md#--importmodule
17731776
[`--test-name-pattern`]: cli.md#--test-name-pattern

lib/internal/test_runner/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const kBuiltinReporters = new SafeMap([
100100
['tap', 'internal/test_runner/reporter/tap'],
101101
]);
102102

103-
const kDefaultReporter = 'tap';
103+
const kDefaultReporter = process.stdout.isTTY ? 'spec' : 'tap';
104104
const kDefaultDestination = 'stdout';
105105

106106
function tryBuiltinReporter(name) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
process.env.FORCE_COLOR = '1';
3+
delete process.env.NODE_DISABLE_COLORS;
4+
delete process.env.NO_COLOR;
5+
6+
require('../common');
7+
const test = require('node:test');
8+
9+
test('should pass', () => {});
10+
test('should fail', () => { throw new Error('fail'); });
11+
test('should skip', { skip: true }, () => {});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[32m* should pass [90m(*ms)[39m[39m
2+
[31m* should fail [90m(*ms)[39m
3+
Error: fail
4+
at * [90m(*)[39m
5+
[90m at *[39m
6+
[90m at *[39m
7+
[90m at *[39m
8+
[90m at *[39m
9+
[90m at *[39m
10+
[90m at *[39m
11+
**
12+
[90m* should skip [90m(*ms)[39m # SKIP[39m
13+
[34m* tests 3[39m
14+
[34m* pass 1[39m
15+
[34m* fail 1[39m
16+
[34m* cancelled 0[39m
17+
[34m* skipped 1[39m
18+
[34m* todo 0[39m
19+
[34m* duration_ms *[39m

0 commit comments

Comments
 (0)