diff --git a/lib/internal/main/test_runner.js b/lib/internal/main/test_runner.js index fda47897da9f06..c68b7f062b5eff 100644 --- a/lib/internal/main/test_runner.js +++ b/lib/internal/main/test_runner.js @@ -31,6 +31,8 @@ if (isUsingInspector() && options.isolation === 'process') { } options.globPatterns = ArrayPrototypeSlice(process.argv, 1); +options.env = process.env; +options.cwd = process.cwd(); debug('test runner configuration:', options); run(options).on('test:summary', (data) => { diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 7f50cc8521bcda..f7251d6dfdb4dd 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -206,8 +206,9 @@ function getRunArgs(path, { forceExit, * An example of such option are --allow-natives-syntax and --expose-gc */ const nodeOptionsSet = new SafeSet(processNodeOptions); + const sourceExecArgv = execArgv.length > 0 ? execArgv : process.execArgv; const unknownProcessExecArgv = ArrayPrototypeFilter( - process.execArgv, + sourceExecArgv, (arg, i, arr) => !nodeOptionsSet.has(arg) && filterExecArgv(arg, i, arr), ); ArrayPrototypePushApply(runArgs, unknownProcessExecArgv); @@ -500,7 +501,7 @@ function runTestFile(path, filesWatcher, opts) { const subtest = opts.root.createSubtest(FileTest, testPath, testOpts, async (t) => { const args = getRunArgs(path, opts); const stdio = ['pipe', 'pipe', 'pipe']; - const env = { __proto__: null, NODE_TEST_CONTEXT: 'child-v8', ...(opts.env || process.env) }; + const env = { __proto__: null, NODE_TEST_CONTEXT: 'child-v8', ...(opts.env ?? {}) }; // Acquire a worker ID from the pool for process isolation mode let workerId; @@ -732,7 +733,7 @@ function run(options = kEmptyObject) { argv = [], cwd = process.cwd(), rerunFailuresFilePath, - env, + env = process.env, } = options; if (files != null) { @@ -907,7 +908,7 @@ function run(options = kEmptyObject) { validatePath(globalSetupPath, 'options.globalSetupPath'); } - if (env != null) { + if ('env' in options) { validateObject(env); if (isolation === 'none') { @@ -997,7 +998,7 @@ function run(options = kEmptyObject) { }; if (isolation === 'process') { - if (process.env.NODE_TEST_CONTEXT !== undefined) { + if ((env?.NODE_TEST_CONTEXT ?? process.env.NODE_TEST_CONTEXT) !== undefined) { process.emitWarning('node:test run() is being called recursively within a test file. skipping running files.'); root.postRun(); return root.reporter;