From 57e148f9875d749c94e787432fc0ceee61de36b8 Mon Sep 17 00:00:00 2001 From: sjwhole Date: Sun, 13 Jul 2025 19:44:10 +0900 Subject: [PATCH 1/2] test_runner: propagate --experimental-config-file to child processes Allow --experimental-config-file to be passed to child test processes while preventing duplicate coverage reports by disabling coverage collection in child processes through NODE_TEST_DISABLE_COVERAGE environment variable. This fixes config file options not being applied in child processes while maintaining the fix for duplicate coverage reports. Fixes: https://github.com/nodejs/node/issues/59021 --- lib/internal/test_runner/runner.js | 3 ++- lib/internal/test_runner/utils.js | 3 ++- .../options-propagation/experimental-config-file.test.mjs | 4 ++-- test/parallel/test-runner-cli.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 958ad1e060fbbe..83de3c63542bb7 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -107,7 +107,6 @@ const kFilterArgs = [ const kFilterArgValues = [ '--test-reporter', '--test-reporter-destination', - '--experimental-config-file', ]; const kDiagnosticsFilterArgs = ['tests', 'suites', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms']; @@ -389,6 +388,8 @@ function runTestFile(path, filesWatcher, opts) { if (opts.root.harness.shouldColorizeTestFiles) { env.FORCE_COLOR = '1'; } + // Prevent coverage reporting in child processes to avoid duplication + env.NODE_TEST_DISABLE_COVERAGE = '1'; const child = spawn( process.execPath, args, diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 44789451d18335..425543866d2744 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -196,7 +196,8 @@ function parseCommandLine() { } const isTestRunner = getOptionValue('--test'); - const coverage = getOptionValue('--experimental-test-coverage'); + const coverage = getOptionValue('--experimental-test-coverage') && + !process.env.NODE_TEST_DISABLE_COVERAGE; const forceExit = getOptionValue('--test-force-exit'); const sourceMaps = getOptionValue('--enable-source-maps'); const updateSnapshots = getOptionValue('--test-update-snapshots'); diff --git a/test/fixtures/test-runner/options-propagation/experimental-config-file.test.mjs b/test/fixtures/test-runner/options-propagation/experimental-config-file.test.mjs index aa36ec2b52d53b..9debfa301e9972 100644 --- a/test/fixtures/test-runner/options-propagation/experimental-config-file.test.mjs +++ b/test/fixtures/test-runner/options-propagation/experimental-config-file.test.mjs @@ -2,7 +2,7 @@ import { test } from 'node:test'; import { strictEqual } from 'node:assert'; import internal from 'internal/options'; -test('it should not receive --experimental-config-file option', () => { +test('it should receive --experimental-config-file option', () => { const optionValue = internal.getOptionValue("--experimental-config-file"); - strictEqual(optionValue, ''); + strictEqual(optionValue, 'node.config.json'); }) diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 287e97861c9285..fbb2951724d711 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -431,7 +431,7 @@ for (const isolation of ['none', 'process']) { } { - // Should not propagate --experimental-config-file option to sub test in isolation process + // Should propagate --experimental-config-file option to sub test in isolation process const fixturePath = join(testFixtures, 'options-propagation'); const args = [ '--test-reporter=tap', From 25b0491767576e9e100afe9097d6128b8d4450d2 Mon Sep 17 00:00:00 2001 From: sjwhole Date: Mon, 14 Jul 2025 15:43:26 +0900 Subject: [PATCH 2/2] test_runner: use NODE_TEST_CONTEXT to disable coverage in child processes Use the existing NODE_TEST_CONTEXT environment variable to prevent duplicate coverage reports in child processes instead of introducing a new NODE_TEST_DISABLE_COVERAGE variable. This approach is more consistent with the existing codebase patterns. The NODE_TEST_CONTEXT variable is already used to identify when running in a child process context, making it the appropriate mechanism for controlling coverage collection behavior. Fixes: https://github.com/nodejs/node/issues/59021 --- lib/internal/test_runner/runner.js | 2 -- lib/internal/test_runner/utils.js | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 83de3c63542bb7..946e1a6c3ec824 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -388,8 +388,6 @@ function runTestFile(path, filesWatcher, opts) { if (opts.root.harness.shouldColorizeTestFiles) { env.FORCE_COLOR = '1'; } - // Prevent coverage reporting in child processes to avoid duplication - env.NODE_TEST_DISABLE_COVERAGE = '1'; const child = spawn( process.execPath, args, diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 425543866d2744..d4ee43179ff299 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -196,8 +196,8 @@ function parseCommandLine() { } const isTestRunner = getOptionValue('--test'); - const coverage = getOptionValue('--experimental-test-coverage') && - !process.env.NODE_TEST_DISABLE_COVERAGE; + const coverage = getOptionValue('--experimental-test-coverage') && + !process.env.NODE_TEST_CONTEXT; const forceExit = getOptionValue('--test-force-exit'); const sourceMaps = getOptionValue('--enable-source-maps'); const updateSnapshots = getOptionValue('--test-update-snapshots');