|
| 1 | +/** |
| 2 | + * Minimal DOM-globals setup for renderer .ts test files that run in the node project |
| 3 | + * but opt into a DOM environment via `// @vitest-environment happy-dom`. |
| 4 | + * |
| 5 | + * This file is added to the node project's `setupFiles` so that it runs for |
| 6 | + * every test in that project. The `typeof window !== 'undefined'` guard makes |
| 7 | + * it a no-op for tests that stay in the real node environment, while tests |
| 8 | + * that declare `// @vitest-environment happy-dom` at the top of their file |
| 9 | + * get the full `window.gitify` context bridge mock they need. |
| 10 | + */ |
| 11 | + |
| 12 | +if (typeof window !== 'undefined') { |
| 13 | + window.gitify = { |
| 14 | + app: { |
| 15 | + version: vi.fn().mockResolvedValue('v0.0.1'), |
| 16 | + hide: vi.fn(), |
| 17 | + quit: vi.fn(), |
| 18 | + show: vi.fn(), |
| 19 | + }, |
| 20 | + twemojiDirectory: vi.fn().mockResolvedValue('/mock/images/assets'), |
| 21 | + openExternalLink: vi.fn(), |
| 22 | + decryptValue: vi.fn().mockResolvedValue('decrypted'), |
| 23 | + encryptValue: vi.fn().mockResolvedValue('encrypted'), |
| 24 | + platform: { |
| 25 | + isLinux: vi.fn().mockReturnValue(false), |
| 26 | + isMacOS: vi.fn().mockReturnValue(true), |
| 27 | + isWindows: vi.fn().mockReturnValue(false), |
| 28 | + }, |
| 29 | + zoom: { |
| 30 | + getLevel: vi.fn(), |
| 31 | + setLevel: vi.fn(), |
| 32 | + }, |
| 33 | + tray: { |
| 34 | + updateColor: vi.fn(), |
| 35 | + updateTitle: vi.fn(), |
| 36 | + useAlternateIdleIcon: vi.fn(), |
| 37 | + useUnreadActiveIcon: vi.fn(), |
| 38 | + }, |
| 39 | + notificationSoundPath: vi.fn(), |
| 40 | + onAuthCallback: vi.fn(), |
| 41 | + onResetApp: vi.fn(), |
| 42 | + onSystemThemeUpdate: vi.fn(), |
| 43 | + setAutoLaunch: vi.fn(), |
| 44 | + applyKeyboardShortcut: vi.fn().mockResolvedValue({ success: true }), |
| 45 | + raiseNativeNotification: vi.fn(), |
| 46 | + }; |
| 47 | + |
| 48 | + Object.defineProperty(navigator, 'clipboard', { |
| 49 | + value: { |
| 50 | + writeText: vi.fn().mockResolvedValue(undefined), |
| 51 | + readText: vi.fn().mockResolvedValue(''), |
| 52 | + }, |
| 53 | + configurable: true, |
| 54 | + }); |
| 55 | +} |
0 commit comments