diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 43a62b5b4307e4..9f54ed0a6d9415 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -358,14 +358,14 @@ class FileTest extends Test { } } -function runTestFile(path, filesWatcher, opts) { +function runTestFile(path, filesWatcher, opts, workerId = 1) { const watchMode = filesWatcher != null; const testPath = path === kIsolatedProcessName ? '' : path; const testOpts = { __proto__: null, signal: opts.signal }; const subtest = opts.root.createSubtest(FileTest, testPath, testOpts, async (t) => { const args = getRunArgs(path, opts); const stdio = ['pipe', 'pipe', 'pipe']; - const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8' }; + const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8', NODE_TEST_WORKER_ID: workerId }; if (watchMode) { stdio.push('ipc'); env.WATCH_REPORT_DEPENDENCIES = '1'; @@ -724,8 +724,10 @@ function run(options = kEmptyObject) { runFiles = () => { root.harness.bootstrapPromise = null; root.harness.buildPromise = null; + let workerId = 1; return SafePromiseAllSettledReturnVoid(testFiles, (path) => { - const subtest = runTestFile(path, filesWatcher, opts); + const subtest = runTestFile(path, filesWatcher, opts, workerId); + workerId++; filesWatcher?.runningSubtests.set(path, subtest); return subtest; }); @@ -766,6 +768,7 @@ function run(options = kEmptyObject) { root.entryFile = resolve(testFile); debug('loading test file:', fileURL.href); + process.env.NODE_TEST_WORKER_ID = 1; try { await cascadedLoader.import(fileURL, parent, { __proto__: null }); } catch (err) {