Files
OpenFrontIO/tests/LangSvg.test.ts
Aotumuri 209de56ae6 Add comprehensive test for lang resource and flag existence (#1643)
## Description:

Checks that each lang file’s lang_code matches its filename and that the
flag SVG exists.
Reports all errors in a single test run for easier debugging.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I have read and accepted the CLA agreement (only required once).

## Please put your Discord username so you can be contacted if a bug or
regression is found:

aotumuri

Co-authored-by: Drills Kibo <59177241+drillskibo@users.noreply.github.com>
2025-09-03 16:06:00 -07:00

54 lines
1.6 KiB
TypeScript

import fs from "fs";
import path from "path";
describe("Lang SVG Field and File Existence Check", () => {
const langDir = path.join(__dirname, "../resources/lang");
const flagDir = path.join(__dirname, "../resources/flags");
test("each lang.json file has a valid lang.svg string and the SVG file exists", () => {
const files = fs
.readdirSync(langDir)
.filter((file) => file.endsWith(".json"));
if (files.length === 0) {
console.log("No resources/lang/*.json files found. Skipping check.");
return;
}
const errors: string[] = [];
for (const file of files) {
try {
const filePath = path.join(langDir, file);
const jsonData = JSON.parse(fs.readFileSync(filePath, "utf-8"));
const langSvg = jsonData.lang?.svg;
if (typeof langSvg !== "string" || langSvg.length === 0) {
errors.push(
`[${file}]: lang.svg is missing or not a non-empty string`,
);
continue;
}
// Check if the SVG file exists in the flags directory
const svgFile = langSvg.endsWith(".svg") ? langSvg : `${langSvg}.svg`;
const flagPath = path.join(flagDir, svgFile);
if (!fs.existsSync(flagPath)) {
errors.push(`[${file}]: SVG file does not exist: ${svgFile}`);
}
} catch (err) {
errors.push(
`[${file}]: Exception occurred - ${(err as Error).message}`,
);
}
}
if (errors.length > 0) {
console.error(
"Lang SVG field or file check failed:\n" + errors.join("\n"),
);
expect(errors).toEqual([]);
}
});
});