Skip to content

Commit 3dd637b

Browse files
committed
fix: only store relevant properties of lighthouse audit
Currently we store the entire Lighthouse audit object in the report which increases the report size and can make the report hard to serialize. These changes only capture the properties we care about.
1 parent f07c013 commit 3dd637b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

runner/workers/serve-testing/lighthouse.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,19 @@ export async function getLighthouseData(
3838
const isAllowedDisplayMode = displayMode === 'binary' || displayMode === 'numeric';
3939

4040
if (audit.score != null && isAllowedType && isAllowedDisplayMode) {
41-
availableAudits.set(audit.id, audit);
41+
availableAudits.set(audit.id, {
42+
// Only capture the properties we care about in order to keep
43+
// the report size small and avoid serialization errors.
44+
id: audit.id,
45+
score: audit.score,
46+
title: audit.title,
47+
displayValue: audit.displayValue ?? null,
48+
description: audit.description,
49+
explanation: audit.explanation ?? null,
50+
scoreDisplayMode: displayMode,
51+
numericValue: audit.numericValue ?? null,
52+
numericUnit: audit.numericUnit ?? null,
53+
});
4254
}
4355
}
4456

runner/workers/serve-testing/worker-types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ export type ServeTestingWorkerResponseMessage =
6666
| ServeTestingProgressLogMessage
6767
| ServeTestingResultMessage;
6868

69-
export type LighthouseAudit = LighthouseRunnerResult['lhr']['audits']['x']; // Lighthouse doesn't export this so we need to dig for it.
69+
export interface LighthouseAudit {
70+
id: string;
71+
score: number | null;
72+
title: string;
73+
displayValue: string | null;
74+
description: string | null;
75+
explanation: string | null;
76+
scoreDisplayMode: 'numeric' | 'binary';
77+
numericValue: number | null;
78+
numericUnit: string | null;
79+
}
7080

7181
export interface LighthouseCategory {
7282
id: string;

0 commit comments

Comments
 (0)