Skip to content

Commit

Permalink
test_runner: support defining test reporter in NODE_OPTIONS
Browse files Browse the repository at this point in the history
Adds --test-reporter and --test-reporter-destination as
allowable options in NODE_OPTIONS.

Fixes nodejs#46484
  • Loading branch information
SRHerzog committed Feb 16, 2023
1 parent cbcefdf commit cfb0ceb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,8 @@ Node.js options that are allowed are:
* `--secure-heap`
* `--snapshot-blob`
* `--test-only`
* `--test-reporter-destination`
* `--test-reporter`
* `--throw-deprecation`
* `--title`
* `--tls-cipher-list`
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ function getRunArgs({ path, inspectPort }) {
return argv;
}

function getNodeOptions(options) {
if (!options) {
return options;
}
return ArrayPrototypeFilter(options.split(' '), filterExecArgv).join(' ');
}

class FileTest extends Test {
#buffer = [];
#checkNestedComment({ comment }) {
Expand Down Expand Up @@ -231,6 +238,7 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
const args = getRunArgs({ path, inspectPort });
const stdio = ['pipe', 'pipe', 'pipe'];
const env = { ...process.env };
env.NODE_OPTIONS = getNodeOptions(process.env.NODE_OPTIONS);
if (filesWatcher) {
stdio.push('ipc');
env.WATCH_REPORT_DEPENDENCIES = '1';
Expand Down
6 changes: 4 additions & 2 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
&EnvironmentOptions::test_name_pattern);
AddOption("--test-reporter",
"report test output using the given reporter",
&EnvironmentOptions::test_reporter);
&EnvironmentOptions::test_reporter,
kAllowedInEnvvar);
AddOption("--test-reporter-destination",
"report given reporter to the given destination",
&EnvironmentOptions::test_reporter_destination);
&EnvironmentOptions::test_reporter_destination,
kAllowedInEnvvar);
AddOption("--test-only",
"run tests with 'only' option set",
&EnvironmentOptions::test_only,
Expand Down

0 comments on commit cfb0ceb

Please sign in to comment.