Skip to content

Build your personal knowledge base with Trilium Notes

client: fix failing tests

Adorian Doran28284eb56aae
diff --git a/apps/desktop/src/main.spec.ts b/apps/desktop/src/main.spec.ts
index b2818bdb6d..6999ca8fa6 100644
--- a/apps/desktop/src/main.spec.ts
+++ b/apps/desktop/src/main.spec.ts
@@ -1,3 +1,4 @@
+import { join as pathJoin } from "node:path";
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
type Handler = (...args: unknown[]) => unknown;
@@ -620,7 +621,10 @@ describe("getUserData()", () => {
it("joins appData with name-port when the env var is unset", async () => {
delete process.env.TRILIUM_ELECTRON_DATA_DIR;
const { getUserData } = await importMain();
- expect(getUserData()).toBe("/appData/Trilium-37740");
+ // Use `path.join` so the assertion matches the platform-native separator
+ // — `getUserData` calls `join(app.getPath("appData"), ...)`, so on Windows
+ // it produces `\appData\Trilium-37740` and on POSIX `/appData/Trilium-37740`.
+ expect(getUserData()).toBe(pathJoin("/appData", "Trilium-37740"));
});
});
diff --git a/apps/desktop/src/services/security_settings.spec.ts b/apps/desktop/src/services/security_settings.spec.ts
index 406ccfc365..4c49db4f94 100644
--- a/apps/desktop/src/services/security_settings.spec.ts
+++ b/apps/desktop/src/services/security_settings.spec.ts
@@ -9,14 +9,22 @@ const h = vi.hoisted(() => ({
// In-memory shim for the security.json path only; every other fs path falls
// through to the real implementation so the server's already-initialised
-// data_dir module is untouched.
+// data_dir module is untouched. Paths ending in `security.json` are treated
+// as fileStore-only (never fall through), so the developer's real
+// `~/…/trilium-data/security.json` on disk can't leak `allowLanAccess: true`
+// (or any other stored value) into a test that expects defaults.
+const isSecurityJsonPath = (p: unknown) => String(p).endsWith("security.json");
vi.mock("fs", async (importOriginal) => {
const actual = await importOriginal<typeof import("fs") & { default?: typeof import("fs") }>();
const real = actual.default ?? actual;
- const existsSync = (p: fs.PathLike) =>
- h.fileStore.has(String(p)) ? true : real.existsSync(p);
- const readFileSync = ((p: fs.PathLike, enc?: unknown) =>
- h.fileStore.has(String(p)) ? h.fileStore.get(String(p)) : real.readFileSync(p, enc as never)) as typeof real.readFileSync;
+ const existsSync = (p: fs.PathLike) => {
+ if (isSecurityJsonPath(p)) return h.fileStore.has(String(p));
+ return real.existsSync(p);
+ };
+ const readFileSync = ((p: fs.PathLike, enc?: unknown) => {
+ if (isSecurityJsonPath(p)) return h.fileStore.get(String(p));
+ return real.readFileSync(p, enc as never);
+ }) as typeof real.readFileSync;
const writeFileSync = ((p: fs.PathLike, data: string) => {
h.fileStore.set(String(p), String(data));
}) as typeof real.writeFileSync;
diff --git a/apps/desktop/src/services/tray.spec.ts b/apps/desktop/src/services/tray.spec.ts
index 6d8862dbe0..d0130cadba 100644
--- a/apps/desktop/src/services/tray.spec.ts
+++ b/apps/desktop/src/services/tray.spec.ts
@@ -1,4 +1,5 @@
import { becca, becca_easy_mocking } from "@triliumnext/core";
+import { join as pathJoin, sep as pathSep } from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
const { buildNote } = becca_easy_mocking;
@@ -680,7 +681,10 @@ describe("tray", () => {
const newWindowItem = instance.lastTemplate.find(
(i) => (i as { label?: string }).label === "tray.open_new_window"
) as Electron.MenuItemConstructorOptions | undefined;
- expect(newWindowItem?.icon).toContain("/res/assets/images/tray/");
+ // Use `path.join` so the substring matches the platform-native
+ // separator — `getIconPath` joins the mocked "/res" with subdirs,
+ // producing `\res\assets\images\tray\...` on Windows.
+ expect(newWindowItem?.icon).toContain(pathJoin("/res", "assets", "images", "tray") + pathSep);
});
});
});