Skip to content

Commit ee77010

Browse files
committed
test_runner: skip --require for test orchestration process
1 parent 9a1e01c commit ee77010

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

lib/internal/process/pre_execution.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ function runEmbedderPreload() {
735735
function loadPreloadModules() {
736736
// For user code, we preload modules if `-r` is passed
737737
const preloadModules = getOptionValue('--require');
738-
if (preloadModules && preloadModules.length > 0) {
738+
const isOrcastrationProcess = getOptionValue('--test');
739+
if (preloadModules && preloadModules.length > 0 && !isOrcastrationProcess) {
739740
const {
740741
Module: {
741742
_preloadModules,
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
console.log({ pid: process.pid });

test/parallel/test-runner-cli.js

+24
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,27 @@ const testFixtures = fixtures.path('test-runner');
334334
assert.match(stdout, /# fail 0/);
335335
assert.match(stdout, /# skipped 0/);
336336
}
337+
338+
{
339+
// --require should only be applied to individual test processes, not the orchestrator
340+
const args = ['--test', '--require', join(testFixtures, 'print_pid.js'), join(testFixtures, 'index.js')];
341+
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
342+
343+
assert.strictEqual(child.status, 1);
344+
assert.strictEqual(child.signal, null);
345+
assert.strictEqual(child.stderr.toString(), '');
346+
assert.match(child.stdout.toString(), /pid: \d+/);
347+
assert.doesNotMatch(child.stdout.toString(), new RegExp(`pid: ${child.pid}`));
348+
}
349+
350+
{
351+
// --import should only be applied to individual test processes, not the orchestrator
352+
const args = ['--test', '--require', join(testFixtures, 'print_pid.js'), join(testFixtures, 'index.js')];
353+
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
354+
355+
assert.strictEqual(child.status, 1);
356+
assert.strictEqual(child.signal, null);
357+
assert.strictEqual(child.stderr.toString(), '');
358+
assert.match(child.stdout.toString(), /pid: \d+/);
359+
assert.doesNotMatch(child.stdout.toString(), new RegExp(`pid: ${child.pid}`));
360+
}

0 commit comments

Comments
 (0)