forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusageAccumulator.test.ts
More file actions
38 lines (33 loc) · 1.32 KB
/
Copy pathusageAccumulator.test.ts
File metadata and controls
38 lines (33 loc) · 1.32 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
import { describe, it, expect } from 'vitest'
import { UsageAccumulator } from './usageAccumulator'
const MAX_GAP = 10_000
describe('UsageAccumulator', () => {
it('credits the earlier sample with the elapsed gap', () => {
const a = new UsageAccumulator(MAX_GAP)
a.addSample('C:\\a\\chrome.exe', 1000)
a.addSample('C:\\a\\chrome.exe', 5000) // +4000ms to chrome
a.addSample('C:\\b\\code.exe', 6000) // +1000ms to chrome
const drained = a.drain()
expect(drained).toEqual([{ exePath: 'C:\\a\\chrome.exe', ms: 5000 }])
})
it('caps gaps larger than maxGap (idle/sleep)', () => {
const a = new UsageAccumulator(MAX_GAP)
a.addSample('C:\\a\\chrome.exe', 1000)
a.addSample('C:\\a\\chrome.exe', 1_000_000) // huge gap → not credited
expect(a.drain()).toEqual([])
})
it('ignores null/empty foreground samples', () => {
const a = new UsageAccumulator(MAX_GAP)
a.addSample(null, 1000)
a.addSample('C:\\a\\chrome.exe', 2000)
a.addSample('C:\\a\\chrome.exe', 4000) // +2000ms
expect(a.drain()).toEqual([{ exePath: 'C:\\a\\chrome.exe', ms: 2000 }])
})
it('drain clears accumulated totals', () => {
const a = new UsageAccumulator(MAX_GAP)
a.addSample('C:\\a\\chrome.exe', 1000)
a.addSample('C:\\a\\chrome.exe', 3000)
a.drain()
expect(a.drain()).toEqual([])
})
})