@@ -116,34 +116,38 @@ if (process.argv.length === 2 &&
116116 require('cluster').isPrimary &&
117117 fs.existsSync(process.argv[1])) {
118118 const { flags, envs } = parseTestMetadata();
119- for (const flag of flags) {
120- if (!process.execArgv.includes(flag) &&
121- // If the binary is build without `intl` the inspect option is
122- // invalid. The test itself should handle this case.
123- (process.features.inspector || !flag.startsWith('--inspect'))) {
124- console.log(
125- 'NOTE: The test started as a child_process using these flags:',
126- inspect(flags),
127- 'And these environment variables:',
128- inspect(envs),
129- 'Use NODE_SKIP_FLAG_CHECK to run the test with the original flags.',
130- );
131- const { spawnSync } = require('child_process');
132- const args = [...flags, ...process.execArgv, ...process.argv.slice(1)];
133- const options = {
134- encoding: 'utf8',
135- stdio: 'inherit',
136- env: {
137- ...process.env,
138- ...envs,
139- },
140- };
141- const result = spawnSync(process.execPath, args, options);
142- if (result.signal) {
143- process.kill(0, result.signal);
144- } else {
145- process.exit(result.status);
146- }
119+
120+ const flagsTriggerSpawn = flags.some((flag) => (
121+ !process.execArgv.includes(flag) &&
122+ // If the binary is build without `intl` the inspect option is
123+ // invalid. The test itself should handle this case.
124+ (process.features.inspector || !flag.startsWith('--inspect'))
125+ ));
126+ const envsTriggerSpawn = Object.keys(envs).some((key) => process.env[key] !== envs[key]);
127+
128+ if (flagsTriggerSpawn || envsTriggerSpawn) {
129+ console.log(
130+ 'NOTE: The test started as a child_process using these flags:',
131+ inspect(flags),
132+ 'And these environment variables:',
133+ inspect(envs),
134+ 'Use NODE_SKIP_FLAG_CHECK to run the test with the original flags.',
135+ );
136+ const { spawnSync } = require('child_process');
137+ const args = [...flags, ...process.execArgv, ...process.argv.slice(1)];
138+ const options = {
139+ encoding: 'utf8',
140+ stdio: 'inherit',
141+ env: {
142+ ...process.env,
143+ ...envs,
144+ },
145+ };
146+ const result = spawnSync(process.execPath, args, options);
147+ if (result.signal) {
148+ process.kill(0, result.signal);
149+ } else {
150+ process.exit(result.status);
147151 }
148152 }
149153}
0 commit comments