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`); + }); + }); });