mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
chore(test/server): always initialize translations
This commit is contained in:
parent
6e4698cf61
commit
43876deefc
20
apps/server/spec/setup.ts
Normal file
20
apps/server/spec/setup.ts
Normal 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")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
@ -1,6 +1,5 @@
|
|||||||
import { beforeAll, describe, expect, it } from "vitest";
|
import { beforeAll, describe, expect, it } from "vitest";
|
||||||
import supertest from "supertest";
|
import supertest from "supertest";
|
||||||
import { initializeTranslations } from "../services/i18n.js";
|
|
||||||
import type { Application } from "express";
|
import type { Application } from "express";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
@ -9,7 +8,6 @@ let app: Application;
|
|||||||
describe("Login Route test", () => {
|
describe("Login Route test", () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
initializeTranslations();
|
|
||||||
const buildApp = (await import("../app.js")).default;
|
const buildApp = (await import("../app.js")).default;
|
||||||
app = await buildApp();
|
app = await buildApp();
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,6 @@ import BNote from "../../becca/entities/bnote.js";
|
|||||||
import TaskContext from "../task_context.js";
|
import TaskContext from "../task_context.js";
|
||||||
import cls from "../cls.js";
|
import cls from "../cls.js";
|
||||||
import sql_init from "../sql_init.js";
|
import sql_init from "../sql_init.js";
|
||||||
import { initializeTranslations } from "../i18n.js";
|
|
||||||
import single from "./single.js";
|
import single from "./single.js";
|
||||||
import stripBom from "strip-bom";
|
import stripBom from "strip-bom";
|
||||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||||
@ -53,7 +52,6 @@ describe("processNoteContent", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
initializeTranslations();
|
|
||||||
sql_init.initializeDb();
|
sql_init.initializeDb();
|
||||||
await sql_init.dbReady;
|
await sql_init.dbReady;
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,6 @@ import BNote from "../../becca/entities/bnote.js";
|
|||||||
import TaskContext from "../task_context.js";
|
import TaskContext from "../task_context.js";
|
||||||
import cls from "../cls.js";
|
import cls from "../cls.js";
|
||||||
import sql_init from "../sql_init.js";
|
import sql_init from "../sql_init.js";
|
||||||
import { initializeTranslations } from "../i18n.js";
|
|
||||||
import { trimIndentation } from "@triliumnext/commons";
|
import { trimIndentation } from "@triliumnext/commons";
|
||||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
@ -45,7 +44,6 @@ describe("processNoteContent", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
initializeTranslations();
|
|
||||||
sql_init.initializeDb();
|
sql_init.initializeDb();
|
||||||
await sql_init.dbReady;
|
await sql_init.dbReady;
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
|
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
import supertest from "supertest";
|
import supertest from "supertest";
|
||||||
import { initializeTranslations } from "../services/i18n.js";
|
|
||||||
import type { Application, Request, Response, NextFunction } from "express";
|
import type { Application, Request, Response, NextFunction } from "express";
|
||||||
import { safeExtractMessageAndStackFromError } from "../services/utils.js";
|
import { safeExtractMessageAndStackFromError } from "../services/utils.js";
|
||||||
|
|
||||||
@ -10,7 +9,6 @@ describe("Share API test", () => {
|
|||||||
let cannotSetHeadersCount = 0;
|
let cannotSetHeadersCount = 0;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
initializeTranslations();
|
|
||||||
const buildApp = (await import("../app.js")).default;
|
const buildApp = (await import("../app.js")).default;
|
||||||
app = await buildApp();
|
app = await buildApp();
|
||||||
app.use((err: unknown, req: Request, res: Response, next: NextFunction) => {
|
app.use((err: unknown, req: Request, res: Response, next: NextFunction) => {
|
||||||
|
@ -8,6 +8,7 @@ export default defineConfig(() => ({
|
|||||||
test: {
|
test: {
|
||||||
watch: false,
|
watch: false,
|
||||||
globals: true,
|
globals: true,
|
||||||
|
setupFiles: ["./spec/setup.ts"],
|
||||||
environment: "node",
|
environment: "node",
|
||||||
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
||||||
reporters: ['default'],
|
reporters: ['default'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user