Skip to content

Commit f12fe6e

Browse files
author
Krsna Suraj
committed
test_runner: capture process state in entry point instead of runner
The run() function in the test runner was directly accessing process.execArgv, process.cwd(), and process.env to configure child processes. This is problematic because run() is part of the public API and should not depend on ambient process state. This commit moves those reads to the CLI entry point (test_runner.js) and passes them as explicit options to run(): - main/test_runner.js: capture process.execArgv, process.env, process.cwd() - runner.js getRunArgs(): use execArgv parameter instead of process.execArgv - runner.js run(): default execArgv to process.execArgv for backward compat Refs: #53867
1 parent 7c53fb5 commit f12fe6e

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

lib/internal/main/test_runner.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ if (isUsingInspector() && options.isolation === 'process') {
3131
}
3232

3333
options.globPatterns = ArrayPrototypeSlice(process.argv, 1);
34+
options.execArgv = ArrayPrototypeSlice(process.execArgv);
35+
options.env = process.env;
36+
options.cwd = process.cwd();
3437

3538
debug('test runner configuration:', options);
3639
run(options).on('test:summary', (data) => {

lib/internal/test_runner/runner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ function getRunArgs(path, { forceExit,
206206
* An example of such option are --allow-natives-syntax and --expose-gc
207207
*/
208208
const nodeOptionsSet = new SafeSet(processNodeOptions);
209+
const sourceExecArgv = execArgv.length > 0 ? execArgv : process.execArgv;
209210
const unknownProcessExecArgv = ArrayPrototypeFilter(
210-
process.execArgv,
211+
sourceExecArgv,
211212
(arg, i, arr) => !nodeOptionsSet.has(arg) && filterExecArgv(arg, i, arr),
212213
);
213214
ArrayPrototypePushApply(runArgs, unknownProcessExecArgv);

0 commit comments

Comments
 (0)