chore(ext/node): pass v8 flags (--expose-gc and --expose-externalize-string) to node test script (#29046)

This commit is contained in:
Yoshiya Hinosawa 2025-04-25 21:22:25 +09:00 committed by GitHub
parent 9ed2fad9ed
commit a44ed9bbe4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 4 deletions

View file

@ -197,7 +197,7 @@ export async function runNodeCompatTestCase(
}
/** Parses the special "Flags:"" syntax in Node.js test files */
function parseFlags(source: string): string[] {
export function parseFlags(source: string): string[] {
const line = /^\/\/ Flags: (.+)$/um.exec(source);
if (line == null) return [];
return line[1].split(" ");

View file

@ -9,7 +9,12 @@ import { pooledMap } from "@std/async/pool";
import { partition } from "@std/collections/partition";
import { stripAnsiCode } from "@std/fmt/colors";
import { version as nodeVersion } from "./runner/suite/node_version.ts";
import { RUN_ARGS, TEST_ARGS, usesNodeTestModule } from "./common.ts";
import {
parseFlags,
RUN_ARGS,
TEST_ARGS,
usesNodeTestModule,
} from "./common.ts";
// The timeout ms for single test execution. If a single test didn't finish in this timeout milliseconds, the test is considered as failure
const TIMEOUT = 2000;
@ -224,6 +229,24 @@ type ErrorUnexpected = {
message: string;
};
function getV8Flags(source: string): string[] {
const v8Flags = [] as string[];
const flags = parseFlags(source);
flags.forEach((flag) => {
switch (flag) {
case "--expose_externalize_string":
v8Flags.push("--expose-externalize-string");
break;
case "--expose-gc":
v8Flags.push("--expose-gc");
break;
default:
break;
}
});
return v8Flags;
}
/**
* Run a single node test file. Retries 3 times on WouldBlock error.
*
@ -233,11 +256,13 @@ async function runSingle(testPath: string, retry = 0): Promise<SingleResult> {
let cmd: Deno.ChildProcess | undefined;
const testPath_ = "tests/node_compat/runner/suite/test/" + testPath;
try {
const usesNodeTest = await Deno.readTextFile(testPath_)
.then(usesNodeTestModule).catch(() => false);
const source = await Deno.readTextFile(testPath_);
const usesNodeTest = usesNodeTestModule(source);
const v8Flags = getV8Flags(source);
cmd = new Deno.Command(Deno.execPath(), {
args: [
...(usesNodeTest ? TEST_ARGS : RUN_ARGS),
...(v8Flags.length > 0 ? ["--v8-flags=" + v8Flags.join(",")] : []),
testPath_,
],
env: {