Skip to content

Commit e9fb4e2

Browse files
committed
add --test-child-process CLI flag
1 parent ed66ea3 commit e9fb4e2

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
lines changed

doc/api/cli.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,12 @@ added: v19.6.0
12721272
The destination for the corresponding test reporter. See the documentation on
12731273
[test reporters][] for more details.
12741274

1275+
### `--test-child-process`
1276+
1277+
A flag to identify the process as a child of another test process to ensure
1278+
that test reporting is formatted correctly to be parsed by a parent test
1279+
process.
1280+
12751281
### `--test-only`
12761282

12771283
<!-- YAML

lib/internal/test_runner/runner.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
ArrayPrototypeSlice,
1010
ArrayPrototypeSome,
1111
ArrayPrototypeSort,
12+
ArrayPrototypeUnshift,
1213
ObjectAssign,
1314
PromisePrototypeThen,
1415
SafePromiseAll,
@@ -130,17 +131,9 @@ function getRunArgs({ path, inspectPort }) {
130131
ArrayPrototypePush(argv, `--inspect-port=${getInspectPort(inspectPort)}`);
131132
}
132133
ArrayPrototypePush(argv, path);
133-
return argv;
134-
}
134+
ArrayPrototypeUnshift(argv, '--test-child-process');
135135

136-
function getNodeOptions(options) {
137-
if (!options) {
138-
return options;
139-
}
140-
return ArrayPrototypeJoin(
141-
ArrayPrototypeFilter(StringPrototypeSplit(options, ' '), filterExecArgv),
142-
' ',
143-
);
136+
return argv;
144137
}
145138

146139
class FileTest extends Test {
@@ -243,7 +236,6 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
243236
const args = getRunArgs({ path, inspectPort });
244237
const stdio = ['pipe', 'pipe', 'pipe'];
245238
const env = { ...process.env };
246-
env.NODE_OPTIONS = getNodeOptions(process.env.NODE_OPTIONS);
247239
if (filesWatcher) {
248240
stdio.push('ipc');
249241
env.WATCH_REPORT_DEPENDENCIES = '1';

lib/internal/test_runner/utils.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,26 @@ async function getReportersMap(reporters, destinations) {
148148

149149

150150
async function setupTestReporters(testsStream) {
151-
const destinations = getOptionValue('--test-reporter-destination');
152-
const reporters = getOptionValue('--test-reporter');
153-
154-
if (reporters.length === 0 && destinations.length === 0) {
155-
ArrayPrototypePush(reporters, kDefaultReporter);
156-
}
151+
let destinations = getOptionValue('--test-reporter-destination');
152+
let reporters = getOptionValue('--test-reporter');
153+
const isChildProcess = getOptionValue('--test-child-process');
154+
155+
if (isChildProcess) {
156+
reporters = [kDefaultReporter];
157+
destinations = [kDefaultDestination];
158+
} else {
159+
if (reporters.length === 0 && destinations.length === 0) {
160+
ArrayPrototypePush(reporters, kDefaultReporter);
161+
}
157162

158-
if (reporters.length === 1 && destinations.length === 0) {
159-
ArrayPrototypePush(destinations, kDefaultDestination);
160-
}
163+
if (reporters.length === 1 && destinations.length === 0) {
164+
ArrayPrototypePush(destinations, kDefaultDestination);
165+
}
161166

162-
if (destinations.length !== reporters.length) {
163-
throw new ERR_INVALID_ARG_VALUE('--test-reporter', reporters,
164-
'must match the number of specified \'--test-reporter-destination\'');
167+
if (destinations.length !== reporters.length) {
168+
throw new ERR_INVALID_ARG_VALUE('--test-reporter', reporters,
169+
'must match the number of specified \'--test-reporter-destination\'');
170+
}
165171
}
166172

167173
const reportersMap = await getReportersMap(reporters, destinations);

src/node_options.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
570570
"report given reporter to the given destination",
571571
&EnvironmentOptions::test_reporter_destination,
572572
kAllowedInEnvvar);
573+
AddOption("--test-child-process", "", // for internal use by test runner
574+
&EnvironmentOptions::test_child_process);
573575
AddOption("--test-only",
574576
"run tests with 'only' option set",
575577
&EnvironmentOptions::test_only,

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class EnvironmentOptions : public Options {
158158
std::vector<std::string> test_name_pattern;
159159
std::vector<std::string> test_reporter;
160160
std::vector<std::string> test_reporter_destination;
161+
bool test_child_process = false;
161162
bool test_only = false;
162163
bool test_udp_no_try_send = false;
163164
bool throw_deprecation = false;

0 commit comments

Comments
 (0)