51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { getRepoRoot, readRepoFile } from "~/utils/testing/repoPaths";
|
|
|
|
const localeFiles = ["apps/web/public/locales/en/translations.json", "apps/web/public/locales/de/translations.json"] as const;
|
|
const sourceRoots = ["apps/web/app", "packages", "server"] as const;
|
|
const ignoredDirectories = new Set(["node_modules", "build", "dist", "coverage", "generated", "__generated__", ".react-router"]);
|
|
const sourceFilePattern = /\.(?:ts|tsx|js|jsx|mjs|cjs)$/u;
|
|
const testFilePattern = /\.(?:test|spec)\.[cm]?[tj]sx?$/u;
|
|
|
|
function collectSourceFiles(root: string, found: string[] = []): string[] {
|
|
if (!fs.existsSync(root)) return found;
|
|
|
|
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
if (entry.name.startsWith(".") || ignoredDirectories.has(entry.name)) continue;
|
|
const absolutePath = path.join(root, entry.name);
|
|
|
|
if (entry.isDirectory()) {
|
|
collectSourceFiles(absolutePath, found);
|
|
continue;
|
|
}
|
|
|
|
if (entry.isFile() && sourceFilePattern.test(entry.name) && !testFilePattern.test(entry.name)) {
|
|
found.push(absolutePath);
|
|
}
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
describe("legacy autogenerated locale keys", () => {
|
|
it("keeps ui.autogenerated out of active locale inventories", () => {
|
|
for (const localeFile of localeFiles) {
|
|
const translations = JSON.parse(readRepoFile(localeFile)) as { ui?: { autogenerated?: unknown } };
|
|
expect(translations.ui?.autogenerated).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it("keeps ui.autogenerated out of active source files", () => {
|
|
const repoRoot = getRepoRoot();
|
|
const offenders = sourceRoots.flatMap((sourceRoot) =>
|
|
collectSourceFiles(path.join(repoRoot, sourceRoot))
|
|
.filter((file) => fs.readFileSync(file, "utf8").includes("ui.autogenerated"))
|
|
.map((file) => path.relative(repoRoot, file))
|
|
);
|
|
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
});
|