Unverified Commit 7233bb07 authored by Hong Minhee's avatar Hong Minhee
Browse files

Run vocab.test.ts on Cloudflare Workers

parent e81b7a5d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -241,11 +241,12 @@ async function loadSchemaValidator(): Promise<Validator> {
  return new Validator(schemaObject as JsonSchema);
}

const schemaValidator: Validator = await loadSchemaValidator();
let schemaValidator: Validator | undefined = undefined;

async function loadSchema(path: string): Promise<TypeSchema> {
  const content = await readFile(path, { encoding: "utf-8" });
  const schema = parse(content);
  if (schemaValidator == null) schemaValidator = await loadSchemaValidator();
  const result = schemaValidator.validate(schema);
  const errors: SchemaError[] = [];
  if (result.valid) return schema as TypeSchema;
+0 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ for await (const file of files) {
    path = path.slice(baseDir.length + SEPARATOR.length);
  }
  if (path.startsWith(`codegen${SEPARATOR}`)) continue;
  else if (path.endsWith(`${SEPARATOR}vocab.test.js`)) continue;
  const relPath = `./${path.replaceAll(SEPARATOR, "/")}`;
  console.log(`import "${relPath}";`);
}
+7 −2
Original line number Diff line number Diff line
@@ -857,7 +857,10 @@ const sampleValues: Record<string, any> = {
  "fedify:units": "m",
};

const types = await loadSchemaFiles(import.meta.dirname!);
const types: Record<string, TypeSchema> =
  navigator?.userAgent === "Cloudflare-Workers"
    ? {} // FIXME: Cloudflare Workers does not support async I/O within global scope
    : await loadSchemaFiles(import.meta.dirname!);
for (const typeUri in types) {
  const type = types[typeUri];
  // @ts-ignore: classes are all different
@@ -1252,7 +1255,9 @@ for (const typeUri in types) {
  });

  if ("Deno" in globalThis) {
    const { assertSnapshot } = await import("@std/testing/snapshot");
    const { assertSnapshot } = await import("@std/testing/snapshot").catch(
      () => ({ assertSnapshot: () => Promise.resolve() }),
    );

    test(`Deno.inspect(${type.name}) [auto]`, async (t) => {
      const empty = new cls({});