mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	chore(test/server): always initialize translations
This commit is contained in:
		
							
								
								
									
										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 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();
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
@@ -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) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -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'],
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user