summaryrefslogtreecommitdiff
path: root/tests/node_compat/test.ts
diff options
context:
space:
mode:
authorsnek <snek@deno.com>2024-08-06 14:52:53 +0200
committerGitHub <noreply@github.com>2024-08-06 12:52:53 +0000
commit897159dc6e1b2319cf2f5f09d8d6cecc0d3175fa (patch)
treecfe4a043d1fc102a4e051b99c7fcbef7b79bbb91 /tests/node_compat/test.ts
parentc0e9512b39a4ed3713d1fd9b28469d0edf68f578 (diff)
feat: vm rewrite (#24596)
rewrite vm implementation to increase compat. vm.Module+importModuleDynamically callbacks should be added in a followup.
Diffstat (limited to 'tests/node_compat/test.ts')
-rw-r--r--tests/node_compat/test.ts31
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