forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforegroundMonitor.linux.test.ts
More file actions
46 lines (40 loc) · 1.38 KB
/
Copy pathforegroundMonitor.linux.test.ts
File metadata and controls
46 lines (40 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
vi.stubGlobal('process', { ...process, platform: 'linux' })
const pruneAppUsage = vi.fn()
const addAppUsage = vi.fn()
const getForegroundExePath = vi.fn(() => '/usr/bin/code')
const subscribeForegroundChange = vi.fn(() => () => {})
vi.mock('../ipc/db', () => ({
pruneAppUsage: (...args: unknown[]) => pruneAppUsage(...args),
addAppUsage: (...args: unknown[]) => addAppUsage(...args)
}))
vi.mock('./nativeForeground', () => ({
getForegroundExePath: () => getForegroundExePath(),
subscribeForegroundChange: () => subscribeForegroundChange()
}))
vi.mock('./usageSettings', () => ({
getUsageSettings: () => ({ enabled: true, retentionDays: 30 })
}))
vi.mock('./usageRetention', () => ({
usageCutoff: () => 0
}))
beforeEach(() => {
vi.resetModules()
pruneAppUsage.mockClear()
addAppUsage.mockClear()
getForegroundExePath.mockClear()
subscribeForegroundChange.mockClear()
})
afterEach(async () => {
const m = await import('./foregroundMonitor')
m.stopForegroundMonitor()
})
describe('foregroundMonitor on linux', () => {
it('starts (does not win32-gate) and prunes', async () => {
const m = await import('./foregroundMonitor')
m.startForegroundMonitor()
expect(pruneAppUsage).toHaveBeenCalledTimes(1)
expect(subscribeForegroundChange).toHaveBeenCalledTimes(1)
m.stopForegroundMonitor()
})
})