Skip to content

Commit cfb0ceb

Browse files
committed
test_runner: support defining test reporter in NODE_OPTIONS
Adds --test-reporter and --test-reporter-destination as allowable options in NODE_OPTIONS. Fixes nodejs#46484
1 parent cbcefdf commit cfb0ceb

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/api/cli.md

+2
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,8 @@ Node.js options that are allowed are:
19521952
* `--secure-heap`
19531953
* `--snapshot-blob`
19541954
* `--test-only`
1955+
* `--test-reporter-destination`
1956+
* `--test-reporter`
19551957
* `--throw-deprecation`
19561958
* `--title`
19571959
* `--tls-cipher-list`

lib/internal/test_runner/runner.js

+8
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ function getRunArgs({ path, inspectPort }) {
131131
return argv;
132132
}
133133

134+
function getNodeOptions(options) {
135+
if (!options) {
136+
return options;
137+
}
138+
return ArrayPrototypeFilter(options.split(' '), filterExecArgv).join(' ');
139+
}
140+
134141
class FileTest extends Test {
135142
#buffer = [];
136143
#checkNestedComment({ comment }) {
@@ -231,6 +238,7 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
231238
const args = getRunArgs({ path, inspectPort });
232239
const stdio = ['pipe', 'pipe', 'pipe'];
233240
const env = { ...process.env };
241+
env.NODE_OPTIONS = getNodeOptions(process.env.NODE_OPTIONS);
234242
if (filesWatcher) {
235243
stdio.push('ipc');
236244
env.WATCH_REPORT_DEPENDENCIES = '1';

src/node_options.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
564564
&EnvironmentOptions::test_name_pattern);
565565
AddOption("--test-reporter",
566566
"report test output using the given reporter",
567-
&EnvironmentOptions::test_reporter);
567+
&EnvironmentOptions::test_reporter,
568+
kAllowedInEnvvar);
568569
AddOption("--test-reporter-destination",
569570
"report given reporter to the given destination",
570-
&EnvironmentOptions::test_reporter_destination);
571+
&EnvironmentOptions::test_reporter_destination,
572+
kAllowedInEnvvar);
571573
AddOption("--test-only",
572574
"run tests with 'only' option set",
573575
&EnvironmentOptions::test_only,

0 commit comments

Comments
 (0)