Skip to content

Commit 93ca474

Browse files
committed
fix(desktop): mock electron in tests that transitively import it
url-guard, csp, and telemetry-policy all reach electron through @/main/navigation but never mocked it, so they depend on a working Electron binary download and fail when that install is incomplete.
1 parent 0513707 commit 93ca474

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

apps/desktop/src/main/browser-agent/url-guard.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest'
22

3+
// url-guard pulls in @/main/navigation, which imports electron.
4+
vi.mock('electron', () => import('@/test/electron-mock'))
5+
36
const { mockLookup } = vi.hoisted(() => ({ mockLookup: vi.fn() }))
47

58
// The real resolveHostAddresses runs; only the resolver under it is mocked, so

apps/desktop/src/main/csp.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest'
2+
3+
// csp pulls in @/main/navigation, which imports electron.
4+
vi.mock('electron', () => import('@/test/electron-mock'))
5+
26
import { attachCspFallback, DEFAULT_DESKTOP_CSP } from '@/main/csp'
37

48
type HeadersReceivedHandler = (

apps/desktop/src/main/telemetry-policy.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { describe, expect, it, vi } from 'vitest'
2+
3+
// telemetry-policy pulls in @/main/navigation, which imports electron.
4+
vi.mock('electron', () => import('@/test/electron-mock'))
5+
26
import { shouldBlockRequest } from '@/main/telemetry-policy'
37

48
describe('shouldBlockRequest', () => {

0 commit comments

Comments
 (0)