Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Apr 1, 2024
1 parent 4fd6635 commit ff52556
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
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
15 changes: 8 additions & 7 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 Expand Up @@ -735,8 +737,7 @@ function runEmbedderPreload() {
function loadPreloadModules() {
// For user code, we preload modules if `-r` is passed
const preloadModules = getOptionValue('--require');
const isOrcastrationProcess = getOptionValue('--test');
if (preloadModules && preloadModules.length > 0 && !isOrcastrationProcess) {
if (preloadModules && preloadModules.length > 0) {
const {
Module: {
_preloadModules,
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ const testFixtures = fixtures.path('test-runner');

{
// --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')];
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);
Expand All @@ -349,7 +350,8 @@ const testFixtures = fixtures.path('test-runner');

{
// --import should only be applied to individual test processes, not the orchestrator
const args = ['--test', '--require', join(testFixtures, 'print_pid.js'), join(testFixtures, 'index.js')];
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);
Expand Down

0 comments on commit ff52556

Please sign in to comment.