test/scripts/locale-groups.test.ts
Rama main · réplica de lectura del repositorio original.
import { expect } from "@std/expect";
import { describe, it as test } from "@std/testing/bdd";
import {
MESSAGE_GROUPS_FILE,
messageGroupsSource,
} from "#scripts/locale-groups/render.ts";
import { projectRoot } from "#scripts/project-root.ts";
describe("messageGroupsSource", () => {
test("lists each catalog's group in order, with its literal type", () => {
expect(messageGroupsSource(["nav.json", "address-lookup.json"])).toBe(
[
"// Generated by `deno task locales:generate` from src/locales/en/. Do not edit.",
"",
"export const MESSAGE_GROUPS = [",
' "address-lookup",',
' "nav",',
"] as const;",
"",
"export type MessageGroup = (typeof MESSAGE_GROUPS)[number];",
"",
].join("\n"),
);
});
test("fails loudly on a file that is not a catalog", () => {
expect(() => messageGroupsSource(["nav.json", "notes.txt"])).toThrow(
"Not a message catalog: src/locales/en/notes.txt",
);
});
});
describe("the generated message group list", () => {
test("matches the catalog files (run deno task locales:generate)", async () => {
const fileNames = Array.from(
Deno.readDirSync(`${projectRoot}/src/locales/en`),
(entry) => entry.name,
);
expect(
await Deno.readTextFile(`${projectRoot}/${MESSAGE_GROUPS_FILE}`),
).toBe(messageGroupsSource(fileNames));
});
});