Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ddf819f

Browse filesBrowse files
SRHerzogdanielleadams
authored andcommitted
test_runner: support defining test reporter in NODE_OPTIONS
Adds --test-reporter and --test-reporter-destination as allowable options in NODE_OPTIONS. Also adds the CLI flag --test-child-process to allow forcing the default test-reporter for inter-process communication. Fixes: #46484 PR-URL: #46688 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent d8d2d33 commit ddf819f
Copy full SHA for ddf819f

File tree

Expand file treeCollapse file tree

4 files changed

+36
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+36
-17
lines changed
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+7Lines changed: 7 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,8 @@ Node.js options that are allowed are:
19151915
* `--secure-heap`
19161916
* `--snapshot-blob`
19171917
* `--test-only`
1918+
* `--test-reporter-destination`
1919+
* `--test-reporter`
19181920
* `--throw-deprecation`
19191921
* `--title`
19201922
* `--tls-cipher-list`
@@ -2056,6 +2058,11 @@ If `value` equals `'1'`, the check for a supported platform is skipped during
20562058
Node.js startup. Node.js might not execute correctly. Any issues encountered
20572059
on unsupported platforms will not be fixed.
20582060

2061+
### `NODE_TEST_CONTEXT=value`
2062+
2063+
If `value` equals `'child'`, test reporter options will be overridden and test
2064+
output will be sent to stdout in the TAP format.
2065+
20592066
### `NODE_TLS_REJECT_UNAUTHORIZED=value`
20602067

20612068
If `value` equals `'0'`, certificate validation is disabled for TLS connections.
Collapse file

‎lib/internal/test_runner/runner.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function getRunArgs({ path, inspectPort }) {
144144
ArrayPrototypePush(argv, `--inspect-port=${getInspectPort(inspectPort)}`);
145145
}
146146
ArrayPrototypePush(argv, path);
147+
147148
return argv;
148149
}
149150

@@ -259,7 +260,7 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
259260
const subtest = root.createSubtest(FileTest, path, async (t) => {
260261
const args = getRunArgs({ path, inspectPort });
261262
const stdio = ['pipe', 'pipe', 'pipe'];
262-
const env = { ...process.env };
263+
const env = { ...process.env, NODE_TEST_CONTEXT: 'child' };
263264
if (filesWatcher) {
264265
stdio.push('ipc');
265266
env.WATCH_REPORT_DEPENDENCIES = '1';
Collapse file

‎lib/internal/test_runner/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/utils.js
+23-14Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
RegExpPrototypeExec,
1010
SafeMap,
1111
} = primordials;
12+
1213
const { basename } = require('path');
1314
const { createWriteStream } = require('fs');
1415
const { pathToFileURL } = require('internal/url');
@@ -167,25 +168,33 @@ function parseCommandLine() {
167168

168169
const isTestRunner = getOptionValue('--test');
169170
const coverage = getOptionValue('--experimental-test-coverage');
170-
const destinations = getOptionValue('--test-reporter-destination');
171-
const reporters = getOptionValue('--test-reporter');
171+
const isChildProcess = process.env.NODE_TEST_CONTEXT === 'child';
172+
let destinations;
173+
let reporters;
172174
let testNamePatterns;
173175
let testOnlyFlag;
174176

175-
if (reporters.length === 0 && destinations.length === 0) {
176-
ArrayPrototypePush(reporters, kDefaultReporter);
177-
}
177+
if (isChildProcess) {
178+
reporters = [kDefaultReporter];
179+
destinations = [kDefaultDestination];
180+
} else {
181+
destinations = getOptionValue('--test-reporter-destination');
182+
reporters = getOptionValue('--test-reporter');
183+
if (reporters.length === 0 && destinations.length === 0) {
184+
ArrayPrototypePush(reporters, kDefaultReporter);
185+
}
178186

179-
if (reporters.length === 1 && destinations.length === 0) {
180-
ArrayPrototypePush(destinations, kDefaultDestination);
181-
}
187+
if (reporters.length === 1 && destinations.length === 0) {
188+
ArrayPrototypePush(destinations, kDefaultDestination);
189+
}
182190

183-
if (destinations.length !== reporters.length) {
184-
throw new ERR_INVALID_ARG_VALUE(
185-
'--test-reporter',
186-
reporters,
187-
'must match the number of specified \'--test-reporter-destination\'',
188-
);
191+
if (destinations.length !== reporters.length) {
192+
throw new ERR_INVALID_ARG_VALUE(
193+
'--test-reporter',
194+
reporters,
195+
'must match the number of specified \'--test-reporter-destination\'',
196+
);
197+
}
189198
}
190199

191200
if (isTestRunner) {
Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
574574
&EnvironmentOptions::test_name_pattern);
575575
AddOption("--test-reporter",
576576
"report test output using the given reporter",
577-
&EnvironmentOptions::test_reporter);
577+
&EnvironmentOptions::test_reporter,
578+
kAllowedInEnvvar);
578579
AddOption("--test-reporter-destination",
579580
"report given reporter to the given destination",
580-
&EnvironmentOptions::test_reporter_destination);
581+
&EnvironmentOptions::test_reporter_destination,
582+
kAllowedInEnvvar);
581583
AddOption("--test-only",
582584
"run tests with 'only' option set",
583585
&EnvironmentOptions::test_only,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.