diff options
Diffstat (limited to 'tests/node_compat/test.ts')
-rw-r--r-- | tests/node_compat/test.ts | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/tests/node_compat/test.ts b/tests/node_compat/test.ts index c9ec1544d..b5c9514a3 100644 --- a/tests/node_compat/test.ts +++ b/tests/node_compat/test.ts @@ -45,6 +45,12 @@ const darwinIgnorePaths = new Set( const decoder = new TextDecoder(); let testSerialId = 0; +function parseFlags(source: string): string[] { + const line = /^\/\/ Flags: (.+)$/um.exec(source); + if (line == null) return []; + return line[1].split(" "); +} + async function runTest(t: Deno.TestContext, path: string): Promise<void> { // If filter patterns are given and any pattern doesn't match // to the file path, then skip the case @@ -69,14 +75,23 @@ async function runTest(t: Deno.TestContext, path: string): Promise<void> { const v8Flags = ["--stack-size=4000"]; const testSource = await Deno.readTextFile(testCase); const envVars: Record<string, string> = {}; - // TODO(kt3k): Parse `Flags` directive correctly - if (testSource.includes("Flags: --expose_externalize_string")) { - v8Flags.push("--expose-externalize-string"); - // TODO(bartlomieju): disable verifying globals if that V8 flag is - // present. Even though we should be able to pass a list of globals - // that are allowed, it doesn't work, because the list is expected to - // contain actual JS objects, not strings :)). - envVars["NODE_TEST_KNOWN_GLOBALS"] = "0"; + const knownGlobals: string[] = []; + parseFlags(testSource).forEach((flag) => { + switch (flag) { + case "--expose_externalize_string": + v8Flags.push("--expose-externalize-string"); + knownGlobals.push("createExternalizableString"); + break; + case "--expose-gc": + v8Flags.push("--expose-gc"); + knownGlobals.push("gc"); + break; + default: + break; + } + }); + if (knownGlobals.length > 0) { + envVars["NODE_TEST_KNOWN_GLOBALS"] = knownGlobals.join(","); } // TODO(nathanwhit): once we match node's behavior on executing // `node:test` tests when we run a file, we can remove this |