Skip to content

Commit

Permalink
add --test-child-process CLI flag
Browse files Browse the repository at this point in the history
  • Loading branch information
SRHerzog committed Feb 22, 2023
1 parent ed66ea3 commit e9fb4e2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
6 changes: 6 additions & 0 deletions doc/api/cli.md
Expand Up @@ -1272,6 +1272,12 @@ added: v19.6.0
The destination for the corresponding test reporter. See the documentation on
[test reporters][] for more details.

### `--test-child-process`

A flag to identify the process as a child of another test process to ensure
that test reporting is formatted correctly to be parsed by a parent test
process.

### `--test-only`

<!-- YAML
Expand Down
14 changes: 3 additions & 11 deletions lib/internal/test_runner/runner.js
Expand Up @@ -9,6 +9,7 @@ const {
ArrayPrototypeSlice,
ArrayPrototypeSome,
ArrayPrototypeSort,
ArrayPrototypeUnshift,
ObjectAssign,
PromisePrototypeThen,
SafePromiseAll,
Expand Down Expand Up @@ -130,17 +131,9 @@ function getRunArgs({ path, inspectPort }) {
ArrayPrototypePush(argv, `--inspect-port=${getInspectPort(inspectPort)}`);
}
ArrayPrototypePush(argv, path);
return argv;
}
ArrayPrototypeUnshift(argv, '--test-child-process');

function getNodeOptions(options) {
if (!options) {
return options;
}
return ArrayPrototypeJoin(
ArrayPrototypeFilter(StringPrototypeSplit(options, ' '), filterExecArgv),
' ',
);
return argv;
}

class FileTest extends Test {
Expand Down Expand Up @@ -243,7 +236,6 @@ 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
30 changes: 18 additions & 12 deletions lib/internal/test_runner/utils.js
Expand Up @@ -148,20 +148,26 @@ async function getReportersMap(reporters, destinations) {


async function setupTestReporters(testsStream) {
const destinations = getOptionValue('--test-reporter-destination');
const reporters = getOptionValue('--test-reporter');

if (reporters.length === 0 && destinations.length === 0) {
ArrayPrototypePush(reporters, kDefaultReporter);
}
let destinations = getOptionValue('--test-reporter-destination');
let reporters = getOptionValue('--test-reporter');
const isChildProcess = getOptionValue('--test-child-process');

if (isChildProcess) {
reporters = [kDefaultReporter];
destinations = [kDefaultDestination];
} else {
if (reporters.length === 0 && destinations.length === 0) {
ArrayPrototypePush(reporters, kDefaultReporter);
}

if (reporters.length === 1 && destinations.length === 0) {
ArrayPrototypePush(destinations, kDefaultDestination);
}
if (reporters.length === 1 && destinations.length === 0) {
ArrayPrototypePush(destinations, kDefaultDestination);
}

if (destinations.length !== reporters.length) {
throw new ERR_INVALID_ARG_VALUE('--test-reporter', reporters,
'must match the number of specified \'--test-reporter-destination\'');
if (destinations.length !== reporters.length) {
throw new ERR_INVALID_ARG_VALUE('--test-reporter', reporters,
'must match the number of specified \'--test-reporter-destination\'');
}
}

const reportersMap = await getReportersMap(reporters, destinations);
Expand Down
2 changes: 2 additions & 0 deletions src/node_options.cc
Expand Up @@ -570,6 +570,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"report given reporter to the given destination",
&EnvironmentOptions::test_reporter_destination,
kAllowedInEnvvar);
AddOption("--test-child-process", "", // for internal use by test runner
&EnvironmentOptions::test_child_process);
AddOption("--test-only",
"run tests with 'only' option set",
&EnvironmentOptions::test_only,
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Expand Up @@ -158,6 +158,7 @@ class EnvironmentOptions : public Options {
std::vector<std::string> test_name_pattern;
std::vector<std::string> test_reporter;
std::vector<std::string> test_reporter_destination;
bool test_child_process = false;
bool test_only = false;
bool test_udp_no_try_send = false;
bool throw_deprecation = false;
Expand Down

0 comments on commit e9fb4e2

Please sign in to comment.