Skip to content

Commit

Permalink
core: move metric savings to audit product (#15074)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed May 18, 2023
1 parent b68a7ea commit 7976210
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 30 deletions.
8 changes: 4 additions & 4 deletions core/audits/server-response-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ class ServerResponseTime extends Audit {
[{url: mainResource.url, responseTime}],
{overallSavingsMs}
);
details.metricSavings = {
FCP: overallSavingsMs,
LCP: overallSavingsMs,
};

return {
numericValue: responseTime,
numericUnit: 'millisecond',
score: Number(passed),
displayValue,
details,
metricSavings: {
FCP: overallSavingsMs,
LCP: overallSavingsMs,
},
};
}
}
Expand Down
8 changes: 8 additions & 0 deletions core/test/audits/server-response-time-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ describe('Performance: server-response-time audit', () => {
overallSavingsMs: 530,
items: [{url: 'https://example.com/', responseTime: 630}],
},
metricSavings: {
FCP: 530,
LCP: 530,
},
});
});

Expand All @@ -50,6 +54,10 @@ describe('Performance: server-response-time audit', () => {
expect(result).toMatchObject({
numericValue: 200,
score: 1,
metricSavings: {
FCP: 100,
LCP: 100,
},
});
});

Expand Down
12 changes: 2 additions & 10 deletions core/test/fixtures/fraggle-rock/reports/sample-flow-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@
"responseTime": 19.687999999999988
}
],
"overallSavingsMs": 0,
"metricSavings": {
"FCP": 0,
"LCP": 0
}
"overallSavingsMs": 0
}
},
"interactive": {
Expand Down Expand Up @@ -16747,11 +16743,7 @@
"responseTime": 10.263
}
],
"overallSavingsMs": 0,
"metricSavings": {
"FCP": 0,
"LCP": 0
}
"overallSavingsMs": 0
}
},
"interactive": {
Expand Down
6 changes: 1 addition & 5 deletions core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,7 @@
"responseTime": 568.468
}
],
"overallSavingsMs": 468.46799999999996,
"metricSavings": {
"FCP": 468.46799999999996,
"LCP": 468.46799999999996
}
"overallSavingsMs": 468.46799999999996
}
},
"interactive": {
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>;
/** [EXPERIMENTAL] 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
9 changes: 0 additions & 9 deletions types/lhr/audit-details.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ interface BaseDetails {
overallSavingsBytes?: number;
/** Additional information, usually used for including debug or meta information in the LHR */
debugData?: Details.DebugData;
/** Estimates of how much this audit affects various performance metrics. Values will be in the unit of the respective metrics. */
metricSavings?: Details.MetricSavings;
}

type Details =
Expand Down Expand Up @@ -306,13 +304,6 @@ declare module Details {
granularity?: number,
}

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

export default Details;
10 changes: 8 additions & 2 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,8 +58,6 @@ 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?: AuditDetails.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

0 comments on commit 7976210

Please sign in to comment.