import { describe, it, expect } from "vitest"; import { readdirSync, readFileSync, statSync } from "node:fs"; import { join, relative } from "node:path"; // unsupported-image-message: a server reason interpolated into a message ("Image upload failed: {message}") may be a // message code, so it goes through t() first. A raw `message: err.message` param would show // the code itself to the admin, untranslated. const ROOT = join(__dirname, "..", ".."); // solvway-admin-portal/app function sources(dir: string): string[] { return readdirSync(dir).flatMap((name) => { const p = join(dir, name); if (statSync(p).isDirectory()) return name === "node_modules" ? [] : sources(p); return /\.tsx?$/.test(name) && !/\.test\.tsx?$/.test(name) ? [p] : []; }); } describe("server reasons interpolated into messages", () => { it("are translated before interpolation", () => { const raw = sources(ROOT).flatMap((file) => readFileSync(file, "utf8").split("\n").flatMap((line, i) => /\bmessage:\s*err\.message\b/.test(line) ? [`${relative(ROOT, file)}:${i + 1}`] : [], ), ); expect(raw).toEqual([]); }); });