test_runner: propagate V8 options to child process

PR-URL: https://github.com/nodejs/node/pull/60999
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
This commit is contained in:
Pietro Marchini 2025-12-09 00:33:03 +01:00 committed by Antoine du Hamel
parent 0624e7a180
commit 410174c3c4
No known key found for this signature in database
GPG Key ID: 20B1A390B168D356
3 changed files with 47 additions and 0 deletions

View File

@ -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');
}

View File

@ -0,0 +1,7 @@
import { describe, it } from "node:test";
describe("test", () => {
it("calls gc", () => {
globalThis.gc();
});
});

View File

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