Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/test-runner/flag-propagation/issue-60986.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, it } from "node:test";

describe("test", () => {
it("calls gc", () => {
globalThis.gc();
});
});
24 changes: 24 additions & 0 deletions test/parallel/test-runner-flag-propagation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually validate this flag made any change. Do we want to pass this?
Maybe instead of calling globalThis.gc() we could check the execArgv inside the test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You absolutely right! Thanks for the suggestion!

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