36 lines
1.6 KiB
TypeScript
36 lines
1.6 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { runI18nCommand } from "../src/i18n-command.ts";
|
|
|
|
test("i18n extract and validate audit native WRN translation keys", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "wrnexus-i18n-cli-"));
|
|
mkdirSync(join(root, "app/pages"), { recursive: true });
|
|
mkdirSync(join(root, "app/locales"), { recursive: true });
|
|
writeFileSync(
|
|
join(root, "app/pages/index.wrn"),
|
|
`page Home { view { <h1>{t:home.title}</h1> } }`,
|
|
);
|
|
writeFileSync(join(root, "app/locales/en.json"), JSON.stringify({ home: { title: "Home" } }));
|
|
writeFileSync(
|
|
join(root, "app/locales/mr.json"),
|
|
JSON.stringify({ home: { title: "मुख्यपृष्ठ" } }),
|
|
);
|
|
expect(runI18nCommand(root, "extract")).toBe(true);
|
|
expect(existsSync(join(root, ".wrnexus/i18n-keys.json"))).toBe(true);
|
|
expect(runI18nCommand(root, "validate")).toBe(true);
|
|
});
|
|
test("i18n validate fails missing locale keys", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "wrnexus-i18n-cli-"));
|
|
mkdirSync(join(root, "app/pages"), { recursive: true });
|
|
mkdirSync(join(root, "app/locales"), { recursive: true });
|
|
writeFileSync(
|
|
join(root, "app/pages/index.wrn"),
|
|
`page Home { view { <h1>{t:home.title}</h1> } }`,
|
|
);
|
|
writeFileSync(join(root, "app/locales/en.json"), JSON.stringify({ home: { title: "Home" } }));
|
|
writeFileSync(join(root, "app/locales/es.json"), JSON.stringify({}));
|
|
expect(runI18nCommand(root, "validate")).toBe(false);
|
|
});
|