This commit is contained in:
62
tests/unit/GuidePerformance.spec.ts
Normal file
62
tests/unit/GuidePerformance.spec.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import {
|
||||
clearGuidePerformanceRecords,
|
||||
getGuidePerformanceRecords,
|
||||
getGuidePerformanceSummary,
|
||||
startGuidePerformance
|
||||
} from '@/services/performance/guidePerformance'
|
||||
|
||||
describe('guidePerformance', () => {
|
||||
beforeEach(() => {
|
||||
clearGuidePerformanceRecords()
|
||||
})
|
||||
|
||||
it('summarizes operation latency and API cache hit rate without start records', () => {
|
||||
const cached = startGuidePerformance('api', 'GET /manifest')
|
||||
cached('cache-hit')
|
||||
const network = startGuidePerformance('api', 'GET /manifest')
|
||||
network('success')
|
||||
const route = startGuidePerformance('interaction', 'route-plan')
|
||||
route('failure')
|
||||
|
||||
expect(getGuidePerformanceSummary()).toEqual(expect.objectContaining({
|
||||
operationCount: 3,
|
||||
apiCacheHitCount: 1,
|
||||
apiNetworkRequestCount: 1,
|
||||
apiCacheHitRate: 0.5,
|
||||
operations: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
kind: 'api',
|
||||
name: 'GET /manifest',
|
||||
count: 2,
|
||||
cacheHitCount: 1,
|
||||
successCount: 1
|
||||
}),
|
||||
expect.objectContaining({
|
||||
kind: 'interaction',
|
||||
name: 'route-plan',
|
||||
failureCount: 1
|
||||
})
|
||||
])
|
||||
}))
|
||||
})
|
||||
|
||||
it('records a start and cache-hit completion for a measured operation', () => {
|
||||
const finish = startGuidePerformance('api', 'GET /gis/sdk/maps/1/manifest')
|
||||
finish('cache-hit', { layer: 'persistent' })
|
||||
|
||||
expect(getGuidePerformanceRecords()).toEqual([
|
||||
expect.objectContaining({
|
||||
kind: 'api',
|
||||
name: 'GET /gis/sdk/maps/1/manifest',
|
||||
outcome: 'start'
|
||||
}),
|
||||
expect.objectContaining({
|
||||
kind: 'api',
|
||||
name: 'GET /gis/sdk/maps/1/manifest',
|
||||
outcome: 'cache-hit',
|
||||
detail: { layer: 'persistent' }
|
||||
})
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user