From f6b6b2e7402efca153d4b61aca5666c70438f68f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 20 Feb 2025 12:42:42 +0200 Subject: [PATCH] feat(test): ensure backend translations are valid JSON --- src/services/i18n.spec.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/services/i18n.spec.ts b/src/services/i18n.spec.ts index 03b4fad62..03d711ae0 100644 --- a/src/services/i18n.spec.ts +++ b/src/services/i18n.spec.ts @@ -3,17 +3,24 @@ import * as i18n from "./i18n.js"; import path from "path"; import fs from "fs"; +function checkTranslations(translationDir: string, translationFileName: string) { + const locales = i18n.getLocales(); + + for (const locale of locales) { + const translationPath = path.join(translationDir, locale.id, translationFileName); + const translationFile = fs.readFileSync(translationPath, { encoding: "utf-8" }); + expect(() => { + JSON.parse(translationFile); + }, `JSON error while parsing locale '${locale.id}' at "${translationPath}"`).not.toThrow(); + } +} + describe("i18n", () => { it("frontend translations are valid JSON", () => { - const translationDir = "src/public/translations"; - const locales = i18n.getLocales(); + checkTranslations("src/public/translations", "translation.json"); + }); - for (const locale of locales) { - const translationPath = path.join(translationDir, locale.id, "translation.json"); - const translationFile = fs.readFileSync(translationPath, { encoding: "utf-8" }); - expect(() => { - JSON.parse(translationFile); - }, `JSON error while parsing locale '${locale.id}' at "${translationPath}"`).not.toThrow(); - } + it("backend translations are valid JSON", () => { + checkTranslations("translations", "server.json"); }); });