Harden RC9 UX and performance states
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
COVERAGE_RESPONSE_BUDGET_MS,
|
||||
MAP_ANALYSIS_BUDGET_MS,
|
||||
exceedsPerformanceBudget,
|
||||
formatPerformanceDuration,
|
||||
} from './performanceBudget'
|
||||
|
||||
describe('release performance budgets', () => {
|
||||
it('keeps coverage stricter than complete map analysis', () => {
|
||||
expect(COVERAGE_RESPONSE_BUDGET_MS).toBe(4_000)
|
||||
expect(MAP_ANALYSIS_BUDGET_MS).toBe(15_000)
|
||||
})
|
||||
|
||||
it('only marks completed work above its budget as slow', () => {
|
||||
expect(exceedsPerformanceBudget(null, 4_000)).toBe(false)
|
||||
expect(exceedsPerformanceBudget(4_000, 4_000)).toBe(false)
|
||||
expect(exceedsPerformanceBudget(4_001, 4_000)).toBe(true)
|
||||
})
|
||||
|
||||
it('formats timings for compact operator feedback', () => {
|
||||
expect(formatPerformanceDuration(null)).toBeNull()
|
||||
expect(formatPerformanceDuration(238)).toBe('238 ms')
|
||||
expect(formatPerformanceDuration(1_250)).toBe('1,3 s')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
export const COVERAGE_RESPONSE_BUDGET_MS = 4_000
|
||||
export const MAP_ANALYSIS_BUDGET_MS = 15_000
|
||||
|
||||
export function exceedsPerformanceBudget(
|
||||
durationMs: number | null,
|
||||
budgetMs: number,
|
||||
): boolean {
|
||||
return durationMs !== null && durationMs > budgetMs
|
||||
}
|
||||
|
||||
export function formatPerformanceDuration(durationMs: number | null): string | null {
|
||||
if (durationMs === null) return null
|
||||
if (durationMs < 1_000) return `${Math.max(1, Math.round(durationMs))} ms`
|
||||
return `${(durationMs / 1_000).toLocaleString('nl-BE', {
|
||||
maximumFractionDigits: 1,
|
||||
minimumFractionDigits: 1,
|
||||
})} s`
|
||||
}
|
||||
Reference in New Issue
Block a user