chore(test/server): always initialize translations

This commit is contained in:
Elian Doran 2025-04-28 17:30:58 +03:00
parent 6e4698cf61
commit 43876deefc
No known key found for this signature in database
6 changed files with 21 additions and 8 deletions

20
apps/server/spec/setup.ts Normal file
View File

@ -0,0 +1,20 @@
import { beforeAll } from "vitest";
import { getResourceDir } from "../src/services/utils.js";
import i18next from "i18next";
import { join } from "path";
beforeAll(async () => {
// Initialize the translations manually to avoid any side effects.
const resourceDir = getResourceDir();
const Backend = (await import("i18next-fs-backend")).default;
// Initialize translations
await i18next.use(Backend).init({
lng: "en",
fallbackLng: "en",
ns: "server",
backend: {
loadPath: join(resourceDir, "assets/translations/{{lng}}/{{ns}}.json")
}
});
});

View File

@ -1,6 +1,5 @@
import { beforeAll, describe, expect, it } from "vitest";
import supertest from "supertest";
import { initializeTranslations } from "../services/i18n.js";
import type { Application } from "express";
import dayjs from "dayjs";
@ -9,7 +8,6 @@ let app: Application;
describe("Login Route test", () => {
beforeAll(async () => {
initializeTranslations();
const buildApp = (await import("../app.js")).default;
app = await buildApp();
});

View File

@ -8,7 +8,6 @@ import BNote from "../../becca/entities/bnote.js";
import TaskContext from "../task_context.js";
import cls from "../cls.js";
import sql_init from "../sql_init.js";
import { initializeTranslations } from "../i18n.js";
import single from "./single.js";
import stripBom from "strip-bom";
const scriptDir = dirname(fileURLToPath(import.meta.url));
@ -53,7 +52,6 @@ describe("processNoteContent", () => {
};
});
initializeTranslations();
sql_init.initializeDb();
await sql_init.dbReady;
});

View File

@ -9,7 +9,6 @@ import BNote from "../../becca/entities/bnote.js";
import TaskContext from "../task_context.js";
import cls from "../cls.js";
import sql_init from "../sql_init.js";
import { initializeTranslations } from "../i18n.js";
import { trimIndentation } from "@triliumnext/commons";
const scriptDir = dirname(fileURLToPath(import.meta.url));
@ -45,7 +44,6 @@ describe("processNoteContent", () => {
};
});
initializeTranslations();
sql_init.initializeDb();
await sql_init.dbReady;
});

View File

@ -1,6 +1,5 @@
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
import supertest from "supertest";
import { initializeTranslations } from "../services/i18n.js";
import type { Application, Request, Response, NextFunction } from "express";
import { safeExtractMessageAndStackFromError } from "../services/utils.js";
@ -10,7 +9,6 @@ describe("Share API test", () => {
let cannotSetHeadersCount = 0;
beforeAll(async () => {
initializeTranslations();
const buildApp = (await import("../app.js")).default;
app = await buildApp();
app.use((err: unknown, req: Request, res: Response, next: NextFunction) => {

View File

@ -8,6 +8,7 @@ export default defineConfig(() => ({
test: {
watch: false,
globals: true,
setupFiles: ["./spec/setup.ts"],
environment: "node",
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],