Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: skip --require for test orchestration process #52099

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/main/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
debug = fn;
});

prepareMainThreadExecution(false);
prepareMainThreadExecution(false, true, false);
markBootstrapComplete();

let concurrency = getOptionValue('--test-concurrency') || true;
Expand Down
12 changes: 7 additions & 5 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ const {
},
} = require('internal/v8/startup_snapshot');

function prepareMainThreadExecution(expandArgv1 = false, initializeModules = true) {
function prepareMainThreadExecution(expandArgv1 = false, initializeModules = true, preloadModules = initializeModules) {
return prepareExecution({
expandArgv1,
initializeModules,
preloadModules,
isMainThread: true,
});
}
Expand All @@ -62,6 +63,7 @@ function prepareWorkerThreadExecution() {
prepareExecution({
expandArgv1: false,
initializeModules: false, // Will need to initialize it after policy setup
preloadModules: false,
isMainThread: false,
});
}
Expand Down Expand Up @@ -95,7 +97,7 @@ function prepareShadowRealmExecution() {
}

function prepareExecution(options) {
const { expandArgv1, initializeModules, isMainThread } = options;
const { expandArgv1, initializeModules, isMainThread, preloadModules } = options;

refreshRuntimeOptions();
reconnectZeroFillToggle();
Expand Down Expand Up @@ -157,7 +159,7 @@ function prepareExecution(options) {
}

if (initializeModules) {
setupUserModules();
setupUserModules(false, preloadModules);
}

return mainEntry;
Expand Down Expand Up @@ -188,7 +190,7 @@ function setupSymbolDisposePolyfill() {
}
}

function setupUserModules(forceDefaultLoader = false) {
function setupUserModules(forceDefaultLoader = false, preloadModules = true) {
initializeCJSLoader();
initializeESMLoader(forceDefaultLoader);
const {
Expand All @@ -203,7 +205,7 @@ function setupUserModules(forceDefaultLoader = false) {
// Do not enable preload modules if custom loaders are disabled.
// For example, loader workers are responsible for doing this themselves.
// And preload modules are not supported in ShadowRealm as well.
if (!forceDefaultLoader) {
if (!forceDefaultLoader && preloadModules) {
loadPreloadModules();
}
// Need to be done after --require setup.
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/test-runner/print_pid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log({ pid: process.pid });
26 changes: 26 additions & 0 deletions test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,29 @@ const testFixtures = fixtures.path('test-runner');
assert.match(stdout, /# fail 0/);
assert.match(stdout, /# skipped 0/);
}

{
// --require should only be applied to individual test processes, not the orchestrator
const args = ['--test', '--require', join(testFixtures, 'print_pid.js'),
join(testFixtures, 'index.js'), join(testFixtures, 'default-behavior', 'index.test.js')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
assert.match(child.stdout.toString(), /pid: \d+/);
assert.doesNotMatch(child.stdout.toString(), new RegExp(`pid: ${child.pid}`));
MoLow marked this conversation as resolved.
Show resolved Hide resolved
}

{
// --import should only be applied to individual test processes, not the orchestrator
const args = ['--test', '--import', fixtures.fileURL('test-runner/print_pid.js'),
join(testFixtures, 'index.js'), join(testFixtures, 'default-behavior', 'index.test.js')];
const child = spawnSync(process.execPath, args, { cwd: testFixtures });

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString(), '');
assert.match(child.stdout.toString(), /pid: \d+/);
assert.doesNotMatch(child.stdout.toString(), new RegExp(`pid: ${child.pid}`));
}