forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf.test.ts
More file actions
41 lines (36 loc) · 1.2 KB
/
Copy pathperf.test.ts
File metadata and controls
41 lines (36 loc) · 1.2 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
import { it, expect, beforeEach, afterEach } from 'vitest'
import { mkdtempSync, readFileSync, rmSync, existsSync } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import { perfMark, flushPerfMarks } from './perf'
let dir: string
beforeEach(() => {
dir = mkdtempSync(join(tmpdir(), 'perf-'))
process.env.OMI_PERF_LOG = join(dir, 'perf.jsonl')
})
afterEach(() => {
delete process.env.OMI_PERF_LOG
rmSync(dir, { recursive: true, force: true })
})
it('writes one JSON line per mark after flush', () => {
perfMark('app:start')
perfMark('db:listX', { ms: 1.5 })
flushPerfMarks()
const lines = readFileSync(process.env.OMI_PERF_LOG!, 'utf8').trim().split('\n')
expect(lines).toHaveLength(2)
const first = JSON.parse(lines[0])
const second = JSON.parse(lines[1])
expect(first.name).toBe('app:start')
expect(typeof first.mono).toBe('number')
expect(typeof first.ts).toBe('number')
expect(second.name).toBe('db:listX')
expect(second.meta.ms).toBe(1.5)
})
it('is a no-op when OMI_PERF_LOG is unset', () => {
delete process.env.OMI_PERF_LOG
expect(() => {
perfMark('app:start')
flushPerfMarks()
}).not.toThrow()
expect(existsSync(join(dir, 'perf.jsonl'))).toBe(false)
})