From 209de56ae6d4d53df4acd6299c229b4c7d33312f Mon Sep 17 00:00:00 2001 From: Aotumuri Date: Tue, 5 Aug 2025 14:13:11 +0900 Subject: [PATCH] Add comprehensive test for lang resource and flag existence (#1643) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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> --- tests/LangSvg.test.ts | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/LangSvg.test.ts diff --git a/tests/LangSvg.test.ts b/tests/LangSvg.test.ts new file mode 100644 index 000000000..3680e8441 --- /dev/null +++ b/tests/LangSvg.test.ts @@ -0,0 +1,53 @@ +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([]); + } + }); +});