Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8807 test(desktop): fail fast when a unit test loads the real electron package (#10163)

Jiayuan Zhang015183fba826
diff --git a/apps/desktop/test/electron-guard.ts b/apps/desktop/test/electron-guard.ts
new file mode 100644
index 0000000000..bdeb38e286
--- /dev/null
+++ b/apps/desktop/test/electron-guard.ts
@@ -0,0 +1,7 @@
+// vitest.config.ts aliases `electron` to this file, so a test that reaches the
+// real package fails here instead. The real package downloads the Electron
+// binary from GitHub on first load: CI never installs it, so an unmocked test
+// passes on a dev machine and fails in CI whenever the release CDN is slow.
+throw new Error(
+ 'This test loaded the real `electron` package. Mock it in the test file with `vi.mock("electron", () => ({ ... }))`, covering the APIs the code under test uses.',
+);
diff --git a/apps/desktop/vitest.config.ts b/apps/desktop/vitest.config.ts
index 49dcb60b26..1baf418df2 100644
--- a/apps/desktop/vitest.config.ts
+++ b/apps/desktop/vitest.config.ts
@@ -5,9 +5,10 @@ import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
resolve: {
- alias: {
- "@": resolve(__dirname, "src/renderer/src"),
- },
+ alias: [
+ { find: "@", replacement: resolve(__dirname, "src/renderer/src") },
+ { find: /^electron$/, replacement: resolve(__dirname, "test/electron-guard.ts") },
+ ],
},
test: {
globals: true,