Skip to content

Commit

Permalink
test_runner: default to spec reporter when on TTY environment
Browse files Browse the repository at this point in the history
PR-URL: #46969
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
MoLow authored and targos committed Mar 13, 2023
1 parent a14cf7d commit 4122a4d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
7 changes: 5 additions & 2 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,7 @@ flags for the test runner to use a specific reporter.
The following built-reporters are supported:

* `tap`
The `tap` reporter is the default reporter used by the test runner. It outputs
the test results in the [TAP][] format.
The `tap` reporter outputs the test results in the [TAP][] format.

* `spec`
The `spec` reporter outputs the test results in a human-readable format.
Expand All @@ -529,6 +528,9 @@ The following built-reporters are supported:
where each passing test is represented by a `.`,
and each failing test is represented by a `X`.

When `stdout` is a [TTY][], the `spec` reporter is used by default.
Otherwise, the `tap` reporter is used by default.

### Custom reporters

[`--test-reporter`][] can be used to specify a path to custom reporter.
Expand Down Expand Up @@ -1732,6 +1734,7 @@ added:
aborted.

[TAP]: https://testanything.org/
[TTY]: tty.md
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
[`--import`]: cli.md#--importmodule
[`--test-name-pattern`]: cli.md#--test-name-pattern
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const kBuiltinReporters = new SafeMap([
['tap', 'internal/test_runner/reporter/tap'],
]);

const kDefaultReporter = 'tap';
const kDefaultReporter = process.stdout.isTTY ? 'spec' : 'tap';
const kDefaultDestination = 'stdout';

function tryBuiltinReporter(name) {
Expand Down
11 changes: 11 additions & 0 deletions test/pseudo-tty/test_runner_default_reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';
process.env.FORCE_COLOR = '1';
delete process.env.NODE_DISABLE_COLORS;
delete process.env.NO_COLOR;

require('../common');
const test = require('node:test');

test('should pass', () => {});
test('should fail', () => { throw new Error('fail'); });
test('should skip', { skip: true }, () => {});
19 changes: 19 additions & 0 deletions test/pseudo-tty/test_runner_default_reporter.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[32m* should pass [90m(*ms)[39m[39m
[31m* should fail [90m(*ms)[39m
Error: fail
at * [90m(*)[39m
[90m at *[39m
[90m at *[39m
[90m at *[39m
[90m at *[39m
[90m at *[39m
[90m at *[39m
**
[90m* should skip [90m(*ms)[39m # SKIP[39m
[34m* tests 3[39m
[34m* pass 1[39m
[34m* fail 1[39m
[34m* cancelled 0[39m
[34m* skipped 1[39m
[34m* todo 0[39m
[34m* duration_ms *[39m

0 comments on commit 4122a4d

Please sign in to comment.