Skip to content

Commit 410174c

Browse files
pmarchiniaduh95
authored andcommitted
test_runner: propagate V8 options to child process
PR-URL: #60999 Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
1 parent 0624e7a commit 410174c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

lib/internal/test_runner/runner.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ function getRunArgs(path, { forceExit,
154154
cwd }) {
155155
const processNodeOptions = getOptionsAsFlagsFromBinding();
156156
const runArgs = ArrayPrototypeFilter(processNodeOptions, filterExecArgv);
157+
158+
/**
159+
* Node supports V8 options passed via cli.
160+
* These options are being consumed by V8 and are not stored in nodeOptions.
161+
*
162+
* We need to propagate these options to the child processes manually.
163+
*
164+
* An example of such option are --allow-natives-syntax and --expose-gc
165+
*/
166+
const nodeOptionsSet = new SafeSet(processNodeOptions);
167+
const unknownProcessExecArgv = ArrayPrototypeFilter(
168+
process.execArgv,
169+
(arg) => !nodeOptionsSet.has(arg),
170+
);
171+
ArrayPrototypePushApply(runArgs, unknownProcessExecArgv);
172+
157173
if (forceExit === true) {
158174
ArrayPrototypePush(runArgs, '--test-force-exit');
159175
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { describe, it } from "node:test";
2+
3+
describe("test", () => {
4+
it("calls gc", () => {
5+
globalThis.gc();
6+
});
7+
});

test/parallel/test-runner-flag-propagation.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,28 @@ describe('test runner flag propagation', () => {
125125
});
126126
}
127127
});
128+
129+
describe('V8 specific flags', () => {
130+
const v8FlagTestFixture = path.join(fixtureDir, 'issue-60986.mjs');
131+
it('should propagate V8 only flags to child tests', () => {
132+
133+
const child = spawnSync(
134+
process.execPath,
135+
[
136+
'--allow-natives-syntax',
137+
'--expose-gc',
138+
'--test',
139+
v8FlagTestFixture,
140+
],
141+
{
142+
cwd: fixtureDir,
143+
},
144+
);
145+
146+
assert.strictEqual(child.status, 0, `V8 flag propagation test failed.`);
147+
const stdout = child.stdout.toString();
148+
assert.match(stdout, /tests 1/, `Test should execute for V8 flag propagation`);
149+
assert.match(stdout, /pass 1/, `Test should pass for V8 flag propagation check`);
150+
});
151+
});
128152
});

0 commit comments

Comments
 (0)