Skip to content

Commit

Permalink
core(preload-lcp-image): enable audit (#13599)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jan 27, 2022
1 parent 8670ea4 commit 9f365f0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
5 changes: 2 additions & 3 deletions lighthouse-core/audits/preload-fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ class PreloadFontsAudit extends Audit {
* @return {Promise<LH.Audit.Product>}
*/
static async audit() {
// Preload advice is dangerous until https://bugs.chromium.org/p/chromium/issues/detail?id=788757
// has been fixed and validated. All preload audits are on hold until then.
// See https://github.com/GoogleChrome/lighthouse/issues/11960 for more discussion.
// Preload advice is on hold until https://github.com/GoogleChrome/lighthouse/issues/11960
// is resolved.
return {score: 1, notApplicable: true};
}
}
Expand Down
12 changes: 1 addition & 11 deletions lighthouse-core/audits/preload-lcp-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class PreloadLCPImageAudit extends Audit {
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static async audit_(artifacts, context) {
static async audit(artifacts, context) {
const gatherContext = artifacts.GatherContext;
const trace = artifacts.traces[PreloadLCPImageAudit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[PreloadLCPImageAudit.DEFAULT_PASS];
Expand Down Expand Up @@ -236,16 +236,6 @@ class PreloadLCPImageAudit extends Audit {
details,
};
}

/**
* @return {Promise<LH.Audit.Product>}
*/
static async audit() {
// Preload advice is dangerous until https://bugs.chromium.org/p/chromium/issues/detail?id=788757
// has been fixed and validated. All preload audits are on hold until then.
// See https://github.com/GoogleChrome/lighthouse/issues/11960 for more discussion.
return {score: 1, notApplicable: true, details: Audit.makeOpportunityDetails([], [], 0)};
}
}

module.exports = PreloadLCPImageAudit;
Expand Down
5 changes: 2 additions & 3 deletions lighthouse-core/audits/uses-rel-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,8 @@ class UsesRelPreloadAudit extends Audit {
* @return {Promise<LH.Audit.Product>}
*/
static async audit() {
// Preload advice is dangerous until https://bugs.chromium.org/p/chromium/issues/detail?id=788757
// has been fixed and validated. All preload audits are on hold until then.
// See https://github.com/GoogleChrome/lighthouse/issues/11960 for more discussion.
// Preload advice is on hold until https://github.com/GoogleChrome/lighthouse/issues/11960
// is resolved.
return {score: 1, notApplicable: true, details: Audit.makeOpportunityDetails([], [], 0)};
}
}
Expand Down
12 changes: 6 additions & 6 deletions lighthouse-core/test/audits/preload-lcp-image-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('Performance: preload-lcp audit', () => {
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl, imageUrl);
artifacts.ImageElements = [];
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit_(artifacts, context);
const results = await PreloadLCPImage.audit(artifacts, context);
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
Expand All @@ -108,7 +108,7 @@ describe('Performance: preload-lcp audit', () => {
networkRecords[3].isLinkPreload = true;
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl, imageUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit_(artifacts, context);
const results = await PreloadLCPImage.audit(artifacts, context);
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
Expand All @@ -119,7 +119,7 @@ describe('Performance: preload-lcp audit', () => {
networkRecords[3].protocol = 'data';
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl, imageUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit_(artifacts, context);
const results = await PreloadLCPImage.audit(artifacts, context);
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
Expand All @@ -129,7 +129,7 @@ describe('Performance: preload-lcp audit', () => {
const networkRecords = mockNetworkRecords();
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl, imageUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit_(artifacts, context);
const results = await PreloadLCPImage.audit(artifacts, context);
expect(results.numericValue).toEqual(180);
expect(results.details.overallSavingsMs).toEqual(180);
expect(results.details.items[0].url).toEqual(imageUrl);
Expand All @@ -141,7 +141,7 @@ describe('Performance: preload-lcp audit', () => {
networkRecords[3].transferSize = 5 * 1000 * 1000;
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl, imageUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit_(artifacts, context);
const results = await PreloadLCPImage.audit(artifacts, context);
expect(results.numericValue).toEqual(30);
expect(results.details.overallSavingsMs).toEqual(30);
expect(results.details.items[0].url).toEqual(imageUrl);
Expand All @@ -153,7 +153,7 @@ describe('Performance: preload-lcp audit', () => {
networkRecords[2].transferSize = 2 * 1000 * 1000;
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl, imageUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit_(artifacts, context);
const results = await PreloadLCPImage.audit(artifacts, context);
expect(results.numericValue).toEqual(30);
expect(results.details.overallSavingsMs).toEqual(30);
expect(results.details.items[0].url).toEqual(imageUrl);
Expand Down
13 changes: 11 additions & 2 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2534,8 +2534,11 @@
"id": "preload-lcp-image",
"title": "Preload Largest Contentful Paint image",
"description": "Preload the image used by the LCP element in order to improve your LCP time. [Learn more](https://web.dev/optimize-lcp/#preload-important-resources).",
"score": null,
"scoreDisplayMode": "notApplicable",
"score": 1,
"scoreDisplayMode": "numeric",
"numericValue": 0,
"numericUnit": "millisecond",
"displayValue": "",
"details": {
"type": "opportunity",
"headings": [],
Expand Down Expand Up @@ -7378,6 +7381,12 @@
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:LanternLargestContentfulPaint",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:csp-xss",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ password-inputs-can-be-pasted-into: pass
performance-budget: notApplicable
plugins: pass
preload-fonts: notApplicable
preload-lcp-image: notApplicable
preload-lcp-image: numeric
pwa-cross-browser: manual
pwa-each-page-has-url: manual
pwa-page-transitions: manual
Expand Down

0 comments on commit 9f365f0

Please sign in to comment.