63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
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' }
|
|
})
|
|
])
|
|
})
|
|
})
|