From 797621008a9b458d190cd31188f6142894810a95 Mon Sep 17 00:00:00 2001 From: Adam Raine <6752989+adamraine@users.noreply.github.com> Date: Thu, 18 May 2023 11:36:48 -0700 Subject: [PATCH] core: move metric savings to audit product (#15074) --- core/audits/server-response-time.js | 8 ++++---- core/test/audits/server-response-time-test.js | 8 ++++++++ .../fraggle-rock/reports/sample-flow-result.json | 12 ++---------- core/test/results/sample_v2.json | 6 +----- types/audit.d.ts | 3 +++ types/lhr/audit-details.d.ts | 9 --------- types/lhr/audit-result.d.ts | 10 ++++++++-- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/core/audits/server-response-time.js b/core/audits/server-response-time.js index a80dde34fa51..41070d7fb755 100644 --- a/core/audits/server-response-time.js +++ b/core/audits/server-response-time.js @@ -76,10 +76,6 @@ class ServerResponseTime extends Audit { [{url: mainResource.url, responseTime}], {overallSavingsMs} ); - details.metricSavings = { - FCP: overallSavingsMs, - LCP: overallSavingsMs, - }; return { numericValue: responseTime, @@ -87,6 +83,10 @@ class ServerResponseTime extends Audit { score: Number(passed), displayValue, details, + metricSavings: { + FCP: overallSavingsMs, + LCP: overallSavingsMs, + }, }; } } diff --git a/core/test/audits/server-response-time-test.js b/core/test/audits/server-response-time-test.js index c89c1cee70d0..da57cc502a8e 100644 --- a/core/test/audits/server-response-time-test.js +++ b/core/test/audits/server-response-time-test.js @@ -29,6 +29,10 @@ describe('Performance: server-response-time audit', () => { overallSavingsMs: 530, items: [{url: 'https://example.com/', responseTime: 630}], }, + metricSavings: { + FCP: 530, + LCP: 530, + }, }); }); @@ -50,6 +54,10 @@ describe('Performance: server-response-time audit', () => { expect(result).toMatchObject({ numericValue: 200, score: 1, + metricSavings: { + FCP: 100, + LCP: 100, + }, }); }); diff --git a/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json b/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json index 708e98612419..28eacb94a288 100644 --- a/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json +++ b/core/test/fixtures/fraggle-rock/reports/sample-flow-result.json @@ -233,11 +233,7 @@ "responseTime": 19.687999999999988 } ], - "overallSavingsMs": 0, - "metricSavings": { - "FCP": 0, - "LCP": 0 - } + "overallSavingsMs": 0 } }, "interactive": { @@ -16747,11 +16743,7 @@ "responseTime": 10.263 } ], - "overallSavingsMs": 0, - "metricSavings": { - "FCP": 0, - "LCP": 0 - } + "overallSavingsMs": 0 } }, "interactive": { diff --git a/core/test/results/sample_v2.json b/core/test/results/sample_v2.json index 5b4edf941125..314b37e07862 100644 --- a/core/test/results/sample_v2.json +++ b/core/test/results/sample_v2.json @@ -336,11 +336,7 @@ "responseTime": 568.468 } ], - "overallSavingsMs": 468.46799999999996, - "metricSavings": { - "FCP": 468.46799999999996, - "LCP": 468.46799999999996 - } + "overallSavingsMs": 468.46799999999996 } }, "interactive": { diff --git a/types/audit.d.ts b/types/audit.d.ts index 25ecd139c345..ae28dafe7b03 100644 --- a/types/audit.d.ts +++ b/types/audit.d.ts @@ -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 */ @@ -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; + /** [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`. */ diff --git a/types/lhr/audit-details.d.ts b/types/lhr/audit-details.d.ts index fc054c6913cf..78634a97b76b 100644 --- a/types/lhr/audit-details.d.ts +++ b/types/lhr/audit-details.d.ts @@ -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 = @@ -306,13 +304,6 @@ declare module Details { granularity?: number, } - interface MetricSavings { - LCP?: number; - FCP?: number; - CLS?: number; - TBT?: number; - INP?: number; - } } export default Details; diff --git a/types/lhr/audit-result.d.ts b/types/lhr/audit-result.d.ts index 48b3146740e4..a9d95fc0cda4 100644 --- a/types/lhr/audit-result.d.ts +++ b/types/lhr/audit-result.d.ts @@ -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; @@ -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. */