From 410174c3c4a3e39ce0f880f610a6cc3c07218151 Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Tue, 9 Dec 2025 00:33:03 +0100 Subject: [PATCH] test_runner: propagate V8 options to child process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/60999 Reviewed-By: Juan José Arboleda Reviewed-By: Chemi Atlow Reviewed-By: Marco Ippolito Reviewed-By: Benjamin Gruenbaum Reviewed-By: Rafael Gonzaga Reviewed-By: Jacob Smith --- lib/internal/test_runner/runner.js | 16 +++++++++++++ .../flag-propagation/issue-60986.mjs | 7 ++++++ test/parallel/test-runner-flag-propagation.js | 24 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/fixtures/test-runner/flag-propagation/issue-60986.mjs diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 2b622e6be39..3f9e855f755 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -154,6 +154,22 @@ function getRunArgs(path, { forceExit, cwd }) { const processNodeOptions = getOptionsAsFlagsFromBinding(); const runArgs = ArrayPrototypeFilter(processNodeOptions, filterExecArgv); + + /** + * Node supports V8 options passed via cli. + * These options are being consumed by V8 and are not stored in nodeOptions. + * + * We need to propagate these options to the child processes manually. + * + * An example of such option are --allow-natives-syntax and --expose-gc + */ + const nodeOptionsSet = new SafeSet(processNodeOptions); + const unknownProcessExecArgv = ArrayPrototypeFilter( + process.execArgv, + (arg) => !nodeOptionsSet.has(arg), + ); + ArrayPrototypePushApply(runArgs, unknownProcessExecArgv); + if (forceExit === true) { ArrayPrototypePush(runArgs, '--test-force-exit'); } diff --git a/test/fixtures/test-runner/flag-propagation/issue-60986.mjs b/test/fixtures/test-runner/flag-propagation/issue-60986.mjs new file mode 100644 index 00000000000..06c9497f724 --- /dev/null +++ b/test/fixtures/test-runner/flag-propagation/issue-60986.mjs @@ -0,0 +1,7 @@ +import { describe, it } from "node:test"; + +describe("test", () => { + it("calls gc", () => { + globalThis.gc(); + }); +}); diff --git a/test/parallel/test-runner-flag-propagation.js b/test/parallel/test-runner-flag-propagation.js index 3248b91bcef..f4e9849cce7 100644 --- a/test/parallel/test-runner-flag-propagation.js +++ b/test/parallel/test-runner-flag-propagation.js @@ -125,4 +125,28 @@ describe('test runner flag propagation', () => { }); } }); + + describe('V8 specific flags', () => { + const v8FlagTestFixture = path.join(fixtureDir, 'issue-60986.mjs'); + it('should propagate V8 only flags to child tests', () => { + + const child = spawnSync( + process.execPath, + [ + '--allow-natives-syntax', + '--expose-gc', + '--test', + v8FlagTestFixture, + ], + { + cwd: fixtureDir, + }, + ); + + assert.strictEqual(child.status, 0, `V8 flag propagation test failed.`); + const stdout = child.stdout.toString(); + assert.match(stdout, /tests 1/, `Test should execute for V8 flag propagation`); + assert.match(stdout, /pass 1/, `Test should pass for V8 flag propagation check`); + }); + }); });