Skip to content

Commit

Permalink
test_runner: always make spec the default reporter
Browse files Browse the repository at this point in the history
This is a breaking change. Prior to this commit, the test_runner
defaulted to the spec reporter if using a TTY, and the TAP
reporter otherwise. This commit makes spec the default reporter
unconditionally. TAP output is still available via the
--test-reporter=tap CLI flag.

Fixes: #54540
PR-URL: #54548
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
  • Loading branch information
cjihrig authored Aug 27, 2024
1 parent ba07067 commit eb7e18f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
11 changes: 4 additions & 7 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1000,12 +1000,13 @@ flags for the test runner to use a specific reporter.

The following built-reporters are supported:

* `spec`
The `spec` reporter outputs the test results in a human-readable format. This
is the default reporter.

* `tap`
The `tap` reporter outputs the test results in the [TAP][] format.

* `spec`
The `spec` reporter outputs the test results in a human-readable format.

* `dot`
The `dot` reporter outputs the test results in a compact format,
where each passing test is represented by a `.`,
Expand All @@ -1018,9 +1019,6 @@ The following built-reporters are supported:
The `lcov` reporter outputs test coverage when used with the
[`--experimental-test-coverage`][] flag.

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

The exact output of these reporters is subject to change between versions of
Node.js, and should not be relied on programmatically. If programmatic access
to the test runner's output is required, use the events emitted by the
Expand Down Expand Up @@ -3505,7 +3503,6 @@ added:
Can be used to abort test subtasks when the test has been aborted.

[TAP]: https://testanything.org/
[TTY]: tty.md
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
[`--experimental-test-snapshots`]: cli.md#--experimental-test-snapshots
[`--import`]: cli.md#--importmodule
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 @@ -119,7 +119,7 @@ const kBuiltinReporters = new SafeMap([
['lcov', 'internal/test_runner/reporter/lcov'],
]);

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

function tryBuiltinReporter(name) {
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-runner-reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ describe('node:test reporters', { concurrency: true }, () => {
it('should default to outputing TAP to stdout', async () => {
const child = spawnSync(process.execPath, ['--test', testFile]);
assert.strictEqual(child.stderr.toString(), '');
assert.match(child.stdout.toString(), /TAP version 13/);
assert.match(child.stdout.toString(), /ok 1 - ok/);
assert.match(child.stdout.toString(), /not ok 2 - failing/);
assert.match(child.stdout.toString(), /ok 2 - top level/);
assert.match(child.stdout.toString(), /✖ failing tests:/);
assert.match(child.stdout.toString(), / ok/);
assert.match(child.stdout.toString(), / failing/);
assert.match(child.stdout.toString(), / top level/);
});

it('should default destination to stdout when passing a single reporter', async () => {
Expand Down

0 comments on commit eb7e18f

Please sign in to comment.