Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(desktop): mock electron
Elian Doran65f4f0d49f00
diff --git a/apps/desktop/src/services/custom_dictionary.spec.ts b/apps/desktop/src/services/custom_dictionary.spec.tsindex 8f318cd4c3..1b3051dd4c 100644--- a/apps/desktop/src/services/custom_dictionary.spec.ts+++ b/apps/desktop/src/services/custom_dictionary.spec.ts@@ -15,6 +15,18 @@ vi.mock("@triliumnext/core", async (importOriginal) => {};});+// `custom_dictionary.ts` does `import electron from "electron"` at module load+// to register IPC handlers. On CI the `electron` package's entry point throws+// ("Electron failed to install correctly") because the binary isn't materialized.+// `loadForSession` (the only thing exercised below) doesn't touch electron at+// runtime, so empty stubs are enough.+vi.mock("electron", () => ({+ default: {+ ipcMain: { on: () => {} },+ app: { on: () => {} }+ }+}));+const customDictionary = await import("./custom_dictionary.js");function mockSession(localWords: string[] = []) {diff --git a/apps/desktop/src/services/shell.spec.ts b/apps/desktop/src/services/shell.spec.tsindex 5eaabd2419..22b4cc3422 100644--- a/apps/desktop/src/services/shell.spec.ts+++ b/apps/desktop/src/services/shell.spec.ts@@ -1,15 +1,28 @@import fs from "fs";import os from "os";import path from "path";-import { afterAll, beforeAll, describe, expect, it } from "vitest";--import {+import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";++// `shell.ts` does `import electron from "electron"` at module load to register+// IPC handlers. On CI the `electron` package's entry point throws ("Electron+// failed to install correctly") because the binary isn't materialized. The+// tests below only exercise pure validators, so stub electron with empty+// surface to skip the binary lookup entirely.+vi.mock("electron", () => ({+ default: {+ ipcMain: { on: () => {}, handle: () => {} },+ shell: {},+ app: {}+ }+}));++const {validateDownloadUrl,validateOpenCustomPath,validateOpenExternalUrl,validateOpenFileUrl,validateOpenPath-} from "./shell.js";+} = await import("./shell.js");//#region validateOpenCustomPath