Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: add metric savings to audit result #14997

Merged
merged 7 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class Audit {
warnings: product.warnings,

details: product.details,
metricSavings: product.metricSavings,
};
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/audits/third-party-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ class ThirdPartySummary extends Audit {
timeInMs: overallSummary.wastedMs,
}),
details,
metricSavings: {
TBT: overallSummary.wastedMs,
adamraine marked this conversation as resolved.
Show resolved Hide resolved
},
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,9 @@
"wastedMs": 0
},
"isEntityGrouped": true
},
"metricSavings": {
"TBT": 0
}
},
"third-party-facades": {
Expand Down Expand Up @@ -8679,6 +8682,9 @@
"wastedMs": 0
},
"isEntityGrouped": true
},
"metricSavings": {
"TBT": 0
}
},
"layout-shift-elements": {
Expand Down Expand Up @@ -17324,6 +17330,9 @@
}
],
"isEntityGrouped": true
},
"metricSavings": {
"TBT": 0
}
},
"third-party-facades": {
Expand Down
3 changes: 3 additions & 0 deletions core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2236,6 +2236,9 @@
"wastedMs": 0
},
"isEntityGrouped": true
},
"metricSavings": {
"TBT": 0
}
},
"third-party-facades": {
Expand Down
3 changes: 3 additions & 0 deletions types/audit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare module Audit {
export type Result = AuditResult.Result;
export type ScoreDisplayMode = AuditResult.ScoreDisplayMode;
export type ScoreDisplayModes = AuditResult.ScoreDisplayModes;
export type MetricSavings = AuditResult.MetricSavings;

type Context = Util.Immutable<{
/** audit options */
Expand Down Expand Up @@ -81,6 +82,8 @@ declare module Audit {
details?: AuditDetails;
/** If an audit encounters unusual execution circumstances, strings can be put in this optional array to add top-level warnings to the LHR. */
runWarnings?: Array<IcuMessage>;
/** Estimates of how much this audit affects various performance metrics. Values will be in the unit of the respective metrics. */
metricSavings?: MetricSavings;
}

/** The Audit.Product type for audits that do not return a `numericValue`. */
Expand Down
10 changes: 10 additions & 0 deletions types/lhr/audit-result.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ interface ScoreDisplayModes {

type ScoreDisplayMode = ScoreDisplayModes[keyof ScoreDisplayModes];

interface MetricSavings {
LCP?: number;
FCP?: number;
CLS?: number;
TBT?: number;
INP?: number;
}

/** Audit result returned in Lighthouse report. All audits offer a description and score of 0-1. */
export interface Result {
displayValue?: string;
Expand All @@ -50,6 +58,8 @@ export interface Result {
id: string;
/** A more detailed description that describes why the audit is important and links to Lighthouse documentation on the audit; markdown links supported. */
description: string;
/** Estimates of how much this audit affects various performance metrics. Values will be in the unit of the respective metrics. */
metricSavings?: MetricSavings;
/** A numeric value that has a meaning specific to the audit, e.g. the number of nodes in the DOM or the timestamp of a specific load event. More information can be found in the audit details, if present. */
numericValue?: number;
/** The unit of `numericValue`, used when the consumer wishes to convert numericValue to a display string. */
Expand Down