summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoshe Atlow <moshe@atlow.co.il>2023-03-06 12:20:51 +0200
committerDanielle Adams <adamzdanielle@gmail.com>2023-04-10 22:18:21 -0400
commit8398f9fcb6f5d08ef9c032d7b256bc15e39fd8e1 (patch)
tree28c7e639ed923ccc6893869c476fe3a7e36c66c5
parent16db3ad1f8c1367d0686a2872e2b8bd2f71326c8 (diff)
downloadnode-new-8398f9fcb6f5d08ef9c032d7b256bc15e39fd8e1.tar.gz
test_runner: default to spec reporter when on TTY environment
PR-URL: https://github.com/nodejs/node/pull/46969 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r--doc/api/test.md7
-rw-r--r--lib/internal/test_runner/utils.js2
-rw-r--r--test/pseudo-tty/test_runner_default_reporter.js11
-rw-r--r--test/pseudo-tty/test_runner_default_reporter.out19
4 files changed, 36 insertions, 3 deletions
diff --git a/doc/api/test.md b/doc/api/test.md
index 00cd263690..b80f31c398 100644
--- a/doc/api/test.md
+++ b/doc/api/test.md
@@ -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.
@@ -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.
@@ -1688,6 +1690,7 @@ added: v18.7.0
aborted.
[TAP]: https://testanything.org/
+[TTY]: tty.md
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
[`--test-name-pattern`]: cli.md#--test-name-pattern
[`--test-only`]: cli.md#--test-only
diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js
index 04427801d4..6fb05070ab 100644
--- a/lib/internal/test_runner/utils.js
+++ b/lib/internal/test_runner/utils.js
@@ -99,7 +99,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) {
diff --git a/test/pseudo-tty/test_runner_default_reporter.js b/test/pseudo-tty/test_runner_default_reporter.js
new file mode 100644
index 0000000000..1c6cda0ebb
--- /dev/null
+++ b/test/pseudo-tty/test_runner_default_reporter.js
@@ -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 }, () => {});
diff --git a/test/pseudo-tty/test_runner_default_reporter.out b/test/pseudo-tty/test_runner_default_reporter.out
new file mode 100644
index 0000000000..795b7e556d
--- /dev/null
+++ b/test/pseudo-tty/test_runner_default_reporter.out
@@ -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