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(prioritize-lcp-image): add LCP savings #15229

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/audits/prioritize-lcp-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class PrioritizeLcpImage extends Audit {
.find(element => element.traceEventType === 'largest-contentful-paint');

if (!lcpElement || lcpElement.type !== 'image') {
return {score: null, notApplicable: true};
return {score: null, notApplicable: true, metricSavings: {LCP: 0}};
}

const mainResource = await MainResource.request({devtoolsLog, URL}, context);
Expand Down Expand Up @@ -286,6 +286,7 @@ class PrioritizeLcpImage extends Audit {
numericUnit: 'millisecond',
displayValue: wastedMs ? str_(i18n.UIStrings.displayValueMsSavings, {wastedMs}) : '',
details,
metricSavings: {LCP: wastedMs},
};
}
}
Expand Down
12 changes: 12 additions & 0 deletions core/test/audits/prioritize-lcp-image-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
expect(result).toEqual({
score: null,
notApplicable: true,
metricSavings: {LCP: 0},
});
});

Expand All @@ -123,6 +124,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
expect(result).toEqual({
score: null,
notApplicable: true,
metricSavings: {LCP: 0},
});
});

Expand All @@ -139,6 +141,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
expect(results.metricSavings).toEqual({LCP: 0});
});

it('shouldn\'t be applicable if the lcp is already preloaded', async () => {
Expand All @@ -149,6 +152,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
expect(results.metricSavings).toEqual({LCP: 0});

// debugData should be included even if image shouldn't be preloaded.
expect(results.details.debugData).toMatchObject({
Expand All @@ -169,6 +173,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
expect(results.metricSavings).toEqual({LCP: 0});
});

it('should suggest preloading a lcp image if all criteria is met', async () => {
Expand All @@ -179,6 +184,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
expect(results.details.overallSavingsMs).toEqual(30);
expect(results.details.items[0].url).toEqual(imageUrl);
expect(results.details.items[0].wastedMs).toEqual(30);
expect(results.metricSavings).toEqual({LCP: 30});

expect(results.details.debugData).toMatchObject({
initiatorPath: [
Expand Down Expand Up @@ -207,6 +213,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
],
pathLength: 3,
});
expect(results.metricSavings).toEqual({LCP: 180});
});

it('should use the initiator path of the first image instance loaded', async () => {
Expand Down Expand Up @@ -235,6 +242,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
pathLength: 2,
},
},
metricSavings: {LCP: 0},
});
});

Expand Down Expand Up @@ -267,6 +275,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
pathLength: 3,
},
},
metricSavings: {LCP: 180},
});
});

Expand Down Expand Up @@ -298,6 +307,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
pathLength: 3,
},
},
metricSavings: {LCP: 180},
});
});

Expand Down Expand Up @@ -337,6 +347,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
pathLength: 4,
},
},
metricSavings: {LCP: 210},
});
});

Expand All @@ -359,6 +370,7 @@ describe('Performance: prioritize-lcp-image audit', () => {
pathLength: 2,
},
},
metricSavings: {LCP: 0},
});
});
});