Skip to content

Commit

Permalink
core(redirects): add FCP and LCP savings (#15228)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianaixba authored Jul 6, 2023
1 parent 67c5c40 commit 81244e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/audits/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ class Redirects extends Audit {
str_(i18n.UIStrings.displayValueMsSavings, {wastedMs: totalWastedMs}) :
'',
details,
metricSavings: {
LCP: totalWastedMs,
FCP: totalWastedMs,
},
};
}
}
Expand Down
10 changes: 10 additions & 0 deletions core/test/audits/redirects-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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});
});
});

Expand All @@ -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});
});
});

Expand All @@ -223,6 +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});
});
});

Expand All @@ -233,6 +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});
});
});

Expand Down Expand Up @@ -262,6 +268,10 @@ describe('Performance: Redirects audit', () => {
{url: 'https://redirect.test/', wastedMs: 0},
],
},
metricSavings: {
LCP: 3000,
FCP: 3000,
},
});
});

Expand Down

0 comments on commit 81244e7

Please sign in to comment.