Files
novalon-website/test-framework/shared/utils/reporting/PerformanceBaseline.ts
T
zhangxiang 602ed6a671 test(hooks): finalize mutation test improvements and release acceptance
- Raise use-swipe-gesture mutation score to 66.13% (target 65%+)
- Maintain use-reduced-motion mutation score at 76.32% (target 50%+)
- Fix use-reduced-motion.ts ESLint set-state-in-effect warning
- Add UJ-10 deep searcher journey (category browse → article read → content discovery)
- Add 40 new test files (analytics, detail, sections, ui, lib components)
- Update test-strategy-plan.md to v2.0 (sync test count to 1591)
- Sync README.md with final release metrics

Quality gates: TS 0 errors, ESLint 0 errors, 121 suites / 1591 tests passed
2026-08-02 19:39:27 +08:00

59 lines
1.7 KiB
TypeScript

// @ts-nocheck
import { TestResult, PerformanceMetrics, ComparisonResult, PerformanceBaseline as PerformanceBaselineType } from '../../types/reporting';
export class PerformanceBaseline {
private baseline: Map<string, PerformanceMetrics> = new Map();
calculate(results: TestResult[]): PerformanceBaselineType {
results.forEach(result => {
if (result.type === 'performance' && result.metrics) {
this.updateBaseline(result);
}
});
const firstBaseline = this.baseline.values().next().value;
return {
timestamp: Date.now(),
metrics: firstBaseline || {
loadTime: 0,
domContentLoaded: 0,
firstContentfulPaint: 0,
largestContentfulPaint: 0,
cumulativeLayoutShift: 0,
firstInputDelay: 0
},
url: ''
};
}
private updateBaseline(result: TestResult): void {
const key = result.name;
const current = this.baseline.get(key);
const metrics = result.metrics as PerformanceMetrics;
if (!current || metrics.loadTime < current.loadTime) {
this.baseline.set(key, metrics);
}
}
compareWithBaseline(metrics: PerformanceMetrics, testName: string): ComparisonResult {
const baseline = this.baseline.get(testName);
if (!baseline) {
return { status: 'no-baseline', difference: 0 };
}
const difference = metrics.loadTime - baseline.loadTime;
const status = difference > 500 ? 'regression' : difference < -500 ? 'improvement' : 'stable';
return { status, difference };
}
getBaseline(testName: string): PerformanceMetrics | undefined {
return this.baseline.get(testName);
}
getAllBaselines(): Map<string, PerformanceMetrics> {
return this.baseline;
}
}