Skip to content

Commit b1b106f

Browse files
committed
Fix TypeScript errors in benchmark files
Add `NumericBenchmarkMetrics` type that excludes object-typed properties (`memoryUsage`, `longTaskMetrics`) for statistical aggregation. Update `BenchmarkSummary` to use this type for mean/min/max/p95/p99/stddev fields.
1 parent 67249e2 commit b1b106f

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

development/page-load-benchmark-pr-comment.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { promises as fs } from 'fs';
22
import path from 'path';
33
import { mean as calculateMean } from 'lodash';
44
import {
5-
BenchmarkMetrics,
65
BenchmarkSummary,
6+
NumericBenchmarkMetrics,
77
} from '../test/e2e/page-objects/benchmark/page-load-benchmark';
88

99
/**
@@ -101,12 +101,12 @@ function aggregateHistoricalBenchmarkData(
101101
const pageData: BenchmarkSummary = {
102102
page: pageName,
103103
samples: 0, // Not used downstream
104-
mean: {} as BenchmarkMetrics,
105-
standardDeviation: {} as BenchmarkMetrics,
106-
min: {} as BenchmarkMetrics,
107-
max: {} as BenchmarkMetrics,
108-
p95: {} as BenchmarkMetrics,
109-
p99: {} as BenchmarkMetrics,
104+
mean: {},
105+
standardDeviation: {},
106+
min: {},
107+
max: {},
108+
p95: {},
109+
p99: {},
110110
};
111111

112112
// Collect mean values for key metrics across all commits
@@ -120,9 +120,7 @@ function aggregateHistoricalBenchmarkData(
120120
// Only collect key metrics
121121
Object.values(KeyMetrics).forEach((metricKey) => {
122122
const metricValue =
123-
pageSummary.mean[
124-
metricKey as keyof Omit<BenchmarkMetrics, 'memoryUsage'>
125-
];
123+
pageSummary.mean[metricKey as keyof NumericBenchmarkMetrics];
126124
if (typeof metricValue === 'number') {
127125
if (!metricMeans[metricKey]) {
128126
metricMeans[metricKey] = [];
@@ -139,7 +137,7 @@ function aggregateHistoricalBenchmarkData(
139137
if (values.length > 0) {
140138
const calculatedMean = calculateMean(values);
141139
pageData.mean[
142-
metricKey as keyof Omit<BenchmarkMetrics, 'memoryUsage'>
140+
metricKey as keyof NumericBenchmarkMetrics
143141
] = calculatedMean;
144142
}
145143
});
@@ -337,10 +335,10 @@ function getMetricValues(
337335
metric: string,
338336
): { mean: number; stdDev: number } | null {
339337
const meanValue =
340-
summary.mean[metric as keyof Omit<BenchmarkMetrics, 'memoryUsage'>];
338+
summary.mean[metric as keyof NumericBenchmarkMetrics];
341339
const stdDevValue =
342340
summary.standardDeviation[
343-
metric as keyof Omit<BenchmarkMetrics, 'memoryUsage'>
341+
metric as keyof NumericBenchmarkMetrics
344342
];
345343

346344
if (typeof meanValue !== 'number') {
@@ -486,13 +484,13 @@ function generateBenchmarkComment(
486484
}
487485

488486
const minValue =
489-
pageSummary.min[metric as keyof Omit<BenchmarkMetrics, 'memoryUsage'>];
487+
pageSummary.min[metric as keyof NumericBenchmarkMetrics];
490488
const maxValue =
491-
pageSummary.max[metric as keyof Omit<BenchmarkMetrics, 'memoryUsage'>];
489+
pageSummary.max[metric as keyof NumericBenchmarkMetrics];
492490
const p95Value =
493-
pageSummary.p95[metric as keyof Omit<BenchmarkMetrics, 'memoryUsage'>];
491+
pageSummary.p95[metric as keyof NumericBenchmarkMetrics];
494492
const p99Value =
495-
pageSummary.p99[metric as keyof Omit<BenchmarkMetrics, 'memoryUsage'>];
493+
pageSummary.p99[metric as keyof NumericBenchmarkMetrics];
496494

497495
comment += `| ${metric} | ${formatTime(currentValues.mean)} | ${formatTime(currentValues.stdDev)} | ${formatTime(minValue || 0)} | ${formatTime(maxValue || 0)} | ${formatTime(p95Value || 0)} | ${formatTime(p99Value || 0)} |\n`;
498496
}

test/e2e/page-objects/benchmark/page-load-benchmark.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ export type BenchmarkMetrics = {
9393
};
9494
};
9595

96+
/**
97+
* Numeric-only benchmark metrics for statistical aggregation.
98+
* Excludes object-typed properties (memoryUsage, longTaskMetrics).
99+
*/
100+
export type NumericBenchmarkMetrics = Omit<
101+
BenchmarkMetrics,
102+
'memoryUsage' | 'longTaskMetrics'
103+
>;
104+
96105
/**
97106
* Individual benchmark measurement result for a single page load test.
98107
* Contains the raw performance metrics for one specific test run.
@@ -118,17 +127,17 @@ export type BenchmarkSummary = {
118127
/** Number of test samples collected for this page */
119128
samples: number;
120129
/** Mean (average) values for each performance metric */
121-
mean: Partial<BenchmarkMetrics>;
130+
mean: Partial<NumericBenchmarkMetrics>;
122131
/** 95th percentile values for each performance metric */
123-
p95: Partial<BenchmarkMetrics>;
132+
p95: Partial<NumericBenchmarkMetrics>;
124133
/** 99th percentile values for each performance metric */
125-
p99: Partial<BenchmarkMetrics>;
134+
p99: Partial<NumericBenchmarkMetrics>;
126135
/** Minimum values for each performance metric */
127-
min: Partial<BenchmarkMetrics>;
136+
min: Partial<NumericBenchmarkMetrics>;
128137
/** Maximum values for each performance metric */
129-
max: Partial<BenchmarkMetrics>;
138+
max: Partial<NumericBenchmarkMetrics>;
130139
/** Standard deviation values for each performance metric */
131-
standardDeviation: Partial<BenchmarkMetrics>;
140+
standardDeviation: Partial<NumericBenchmarkMetrics>;
132141
};
133142

134143
/**
@@ -453,10 +462,9 @@ export class PageLoadBenchmark {
453462

454463
for (const [page, pageResults] of Object.entries(resultsByPage)) {
455464
const metrics = pageResults.map((r) => r.metrics);
456-
const metricKeys = Object.keys(metrics[0]) as (keyof Omit<
457-
BenchmarkMetrics,
458-
'memoryUsage'
459-
>)[];
465+
const metricKeys = Object.keys(metrics[0]).filter(
466+
(k) => k !== 'memoryUsage' && k !== 'longTaskMetrics',
467+
) as (keyof NumericBenchmarkMetrics)[];
460468

461469
const summary: BenchmarkSummary = {
462470
page,

0 commit comments

Comments
 (0)