From ed736563f6ab8eb90dec0b7a567bf1ee85b6af6a Mon Sep 17 00:00:00 2001 From: Adriana Ixba Date: Thu, 6 Jul 2023 14:31:40 -0700 Subject: [PATCH 1/2] add savings to redirect audit --- core/audits/redirects.js | 4 ++++ core/test/audits/redirects-test.js | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/audits/redirects.js b/core/audits/redirects.js index 7c3bd2ccbee1..fb911b85f805 100644 --- a/core/audits/redirects.js +++ b/core/audits/redirects.js @@ -154,6 +154,10 @@ class Redirects extends Audit { str_(i18n.UIStrings.displayValueMsSavings, {wastedMs: totalWastedMs}) : '', details, + metricSavings: { + LCP: totalWastedMs, + FCP: totalWastedMs, + } }; } } diff --git a/core/test/audits/redirects-test.js b/core/test/audits/redirects-test.js index b0a095e885a6..5b66da8bfb96 100644 --- a/core/test/audits/redirects-test.js +++ b/core/test/audits/redirects-test.js @@ -164,6 +164,7 @@ describe('Performance: Redirects audit', () => { expect(output.details.items).toHaveLength(3); expect(Math.round(output.score * 100) / 100).toMatchInlineSnapshot(`0.29`); expect(output.numericValue).toMatchInlineSnapshot(`2000`); + expect(output.metricSavings).toEqual({LCP:2000, FCP:2000 }); }); it('uses lantern timings when throttlingMethod is simulate', async () => { @@ -192,6 +193,7 @@ describe('Performance: Redirects audit', () => { ] `); expect(output.numericValue).toMatchInlineSnapshot(`1890`); + expect(output.metricSavings).toEqual({LCP:1890, FCP:1890 }); }); it('fails when 3 redirects detected', () => { @@ -201,6 +203,7 @@ describe('Performance: Redirects audit', () => { expect(output.details.items).toHaveLength(4); expect(Math.round(output.score * 100) / 100).toMatchInlineSnapshot(`0.2`); expect(output.numericValue).toMatchInlineSnapshot(`3000`); + expect(output.metricSavings).toEqual({LCP:3000, FCP:3000 }); }); }); @@ -211,6 +214,7 @@ describe('Performance: Redirects audit', () => { expect(output.details.items).toHaveLength(3); expect(Math.round(output.score * 100) / 100).toMatchInlineSnapshot(`0.29`); expect(output.numericValue).toMatchInlineSnapshot(`2000`); + expect(output.metricSavings).toEqual({LCP:2000, FCP:2000 }); }); }); @@ -223,6 +227,8 @@ describe('Performance: Redirects audit', () => { expect(output.details.items).toHaveLength(2); expect(output.score).toEqual(1); expect(output.numericValue).toMatchInlineSnapshot(`1000`); + expect(output.metricSavings).toEqual({LCP:1000, FCP:1000 }); + }); }); @@ -233,6 +239,7 @@ describe('Performance: Redirects audit', () => { assert.equal(output.score, 1); assert.equal(output.details.items.length, 0); assert.equal(output.numericValue, 0); + assert.deepStrictEqual(output.metricSavings, {LCP: 0, FCP:0}); }); }); @@ -262,6 +269,10 @@ describe('Performance: Redirects audit', () => { {url: 'https://redirect.test/', wastedMs: 0}, ], }, + metricSavings: { + LCP: 3000, + FCP: 3000, + } }); }); From 65cfddb49147fb0c733b5a0af568c2953047ba0d Mon Sep 17 00:00:00 2001 From: Adriana Ixba Date: Thu, 6 Jul 2023 14:45:51 -0700 Subject: [PATCH 2/2] lint fix --- core/audits/redirects.js | 2 +- core/test/audits/redirects-test.js | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core/audits/redirects.js b/core/audits/redirects.js index fb911b85f805..7057954658f0 100644 --- a/core/audits/redirects.js +++ b/core/audits/redirects.js @@ -157,7 +157,7 @@ class Redirects extends Audit { metricSavings: { LCP: totalWastedMs, FCP: totalWastedMs, - } + }, }; } } diff --git a/core/test/audits/redirects-test.js b/core/test/audits/redirects-test.js index 5b66da8bfb96..374b425b92fd 100644 --- a/core/test/audits/redirects-test.js +++ b/core/test/audits/redirects-test.js @@ -164,7 +164,7 @@ describe('Performance: Redirects audit', () => { expect(output.details.items).toHaveLength(3); expect(Math.round(output.score * 100) / 100).toMatchInlineSnapshot(`0.29`); expect(output.numericValue).toMatchInlineSnapshot(`2000`); - expect(output.metricSavings).toEqual({LCP:2000, FCP:2000 }); + expect(output.metricSavings).toEqual({LCP: 2000, FCP: 2000}); }); it('uses lantern timings when throttlingMethod is simulate', async () => { @@ -193,7 +193,7 @@ describe('Performance: Redirects audit', () => { ] `); expect(output.numericValue).toMatchInlineSnapshot(`1890`); - expect(output.metricSavings).toEqual({LCP:1890, FCP:1890 }); + expect(output.metricSavings).toEqual({LCP: 1890, FCP: 1890}); }); it('fails when 3 redirects detected', () => { @@ -203,7 +203,7 @@ describe('Performance: Redirects audit', () => { expect(output.details.items).toHaveLength(4); expect(Math.round(output.score * 100) / 100).toMatchInlineSnapshot(`0.2`); expect(output.numericValue).toMatchInlineSnapshot(`3000`); - expect(output.metricSavings).toEqual({LCP:3000, FCP:3000 }); + expect(output.metricSavings).toEqual({LCP: 3000, FCP: 3000}); }); }); @@ -214,7 +214,7 @@ describe('Performance: Redirects audit', () => { expect(output.details.items).toHaveLength(3); expect(Math.round(output.score * 100) / 100).toMatchInlineSnapshot(`0.29`); expect(output.numericValue).toMatchInlineSnapshot(`2000`); - expect(output.metricSavings).toEqual({LCP:2000, FCP:2000 }); + expect(output.metricSavings).toEqual({LCP: 2000, FCP: 2000}); }); }); @@ -227,8 +227,7 @@ describe('Performance: Redirects audit', () => { expect(output.details.items).toHaveLength(2); expect(output.score).toEqual(1); expect(output.numericValue).toMatchInlineSnapshot(`1000`); - expect(output.metricSavings).toEqual({LCP:1000, FCP:1000 }); - + expect(output.metricSavings).toEqual({LCP: 1000, FCP: 1000}); }); }); @@ -239,7 +238,7 @@ describe('Performance: Redirects audit', () => { assert.equal(output.score, 1); assert.equal(output.details.items.length, 0); assert.equal(output.numericValue, 0); - assert.deepStrictEqual(output.metricSavings, {LCP: 0, FCP:0}); + assert.deepStrictEqual(output.metricSavings, {LCP: 0, FCP: 0}); }); }); @@ -272,7 +271,7 @@ describe('Performance: Redirects audit', () => { metricSavings: { LCP: 3000, FCP: 3000, - } + }, }); });