Skip to content

Commit

Permalink
core: rename preload-lcp-image to prioritize-lcp-image (#14761)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Feb 8, 2023
1 parent 0b8c63d commit de6b53a
Show file tree
Hide file tree
Showing 60 changed files with 88 additions and 362 deletions.
2 changes: 1 addition & 1 deletion cli/test/smokehouse/test-definitions/dobetterweb.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ const expectations = {
],
},
},
'preload-lcp-image': {
'prioritize-lcp-image': {
score: 1,
numericValue: 0,
details: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const expectations = {
},
},
},
'preload-lcp-image': {
'prioritize-lcp-image': {
score: 1,
numericValue: 0,
details: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
* @typedef {Array<{url: string, initiatorType: string}>} InitiatorPath
*/

class PreloadLCPImageAudit extends Audit {
class PrioritizeLcpImage extends Audit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'preload-lcp-image',
id: 'prioritize-lcp-image',
title: str_(UIStrings.title),
description: str_(UIStrings.description),
supportedModes: ['navigation'],
Expand Down Expand Up @@ -92,11 +92,11 @@ class PreloadLCPImageAudit extends Audit {
*/
static getLCPNodeToPreload(mainResource, graph, lcpUrl) {
if (!lcpUrl) return {};
const {lcpNode, path} = PreloadLCPImageAudit.findLCPNode(graph, lcpUrl);
const {lcpNode, path} = PrioritizeLcpImage.findLCPNode(graph, lcpUrl);
if (!lcpNode || !path) return {};

// eslint-disable-next-line max-len
const shouldPreload = PreloadLCPImageAudit.shouldPreloadRequest(lcpNode.record, mainResource, path);
const shouldPreload = PrioritizeLcpImage.shouldPreloadRequest(lcpNode.record, mainResource, path);
const lcpNodeToPreload = shouldPreload ? lcpNode : undefined;

const initiatorPath = [
Expand Down Expand Up @@ -230,8 +230,8 @@ class PreloadLCPImageAudit extends Audit {
*/
static async audit(artifacts, context) {
const gatherContext = artifacts.GatherContext;
const trace = artifacts.traces[PreloadLCPImageAudit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[PreloadLCPImageAudit.DEFAULT_PASS];
const trace = artifacts.traces[PrioritizeLcpImage.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[PrioritizeLcpImage.DEFAULT_PASS];
const URL = artifacts.URL;
const metricData = {trace, devtoolsLog, gatherContext, settings: context.settings, URL};
const lcpElement = artifacts.TraceElements
Expand All @@ -248,13 +248,13 @@ class PreloadLCPImageAudit extends Audit {
LoadSimulator.request({devtoolsLog, settings: context.settings}, context),
]);

const lcpUrl = PreloadLCPImageAudit.getLcpUrl(trace, processedNavigation);
const lcpUrl = PrioritizeLcpImage.getLcpUrl(trace, processedNavigation);
const graph = lanternLCP.pessimisticGraph;
// eslint-disable-next-line max-len
const {lcpNodeToPreload, initiatorPath} = PreloadLCPImageAudit.getLCPNodeToPreload(mainResource, graph, lcpUrl);
const {lcpNodeToPreload, initiatorPath} = PrioritizeLcpImage.getLCPNodeToPreload(mainResource, graph, lcpUrl);

const {results, wastedMs} =
PreloadLCPImageAudit.computeWasteWithGraph(lcpElement, lcpNodeToPreload, graph, simulator);
PrioritizeLcpImage.computeWasteWithGraph(lcpElement, lcpNodeToPreload, graph, simulator);

/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
Expand Down Expand Up @@ -286,5 +286,5 @@ class PreloadLCPImageAudit extends Audit {
}
}

export default PreloadLCPImageAudit;
export default PrioritizeLcpImage;
export {UIStrings};
4 changes: 2 additions & 2 deletions core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const defaultConfig = {
'non-composited-animations',
'unsized-images',
'valid-source-maps',
'preload-lcp-image',
'prioritize-lcp-image',
'csp-xss',
'script-treemap-data',
'manual/pwa-cross-browser',
Expand Down Expand Up @@ -446,7 +446,7 @@ const defaultConfig = {
{id: 'efficient-animated-content', weight: 0},
{id: 'duplicated-javascript', weight: 0},
{id: 'legacy-javascript', weight: 0},
{id: 'preload-lcp-image', weight: 0},
{id: 'prioritize-lcp-image', weight: 0},
{id: 'total-byte-weight', weight: 0},
{id: 'uses-long-cache-ttl', weight: 0},
{id: 'dom-size', weight: 0},
Expand Down
2 changes: 1 addition & 1 deletion core/config/metrics-to-audits.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const fcpRelevantAudits = [
const lcpRelevantAudits = [
...fcpRelevantAudits,
'largest-contentful-paint-element',
'preload-lcp-image',
'prioritize-lcp-image',
'unused-javascript',
'efficient-animated-content',
'total-byte-weight',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

import PreloadLCPImage from '../../audits/preload-lcp-image.js';
import PrioritizeLcpImage from '../../audits/prioritize-lcp-image.js';
import {networkRecordsToDevtoolsLog} from '../network-records-to-devtools-log.js';
import {createTestTrace} from '../create-test-trace.js';

Expand All @@ -13,17 +13,19 @@ const mainDocumentNodeUrl = 'http://www.example.com:3000';
const scriptNodeUrl = 'http://www.example.com/script.js';
const imageUrl = 'http://www.example.com/image.png';

describe('Performance: preload-lcp audit', () => {
describe('Performance: prioritize-lcp-image audit', () => {
const mockArtifacts = (networkRecords, finalDisplayedUrl) => {
return {
GatherContext: {gatherMode: 'navigation'},
traces: {
[PreloadLCPImage.DEFAULT_PASS]: createTestTrace({
[PrioritizeLcpImage.DEFAULT_PASS]: createTestTrace({
traceEnd: 6e3,
largestContentfulPaint: 45e2,
}),
},
devtoolsLogs: {[PreloadLCPImage.DEFAULT_PASS]: networkRecordsToDevtoolsLog(networkRecords)},
devtoolsLogs: {
[PrioritizeLcpImage.DEFAULT_PASS]: networkRecordsToDevtoolsLog(networkRecords),
},
URL: {
requestedUrl: finalDisplayedUrl,
mainDocumentUrl: finalDisplayedUrl,
Expand Down Expand Up @@ -92,7 +94,7 @@ describe('Performance: preload-lcp audit', () => {
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl);
artifacts.TraceElements = [];
const context = {settings: {}, computedCache: new Map()};
const result = await PreloadLCPImage.audit(artifacts, context);
const result = await PrioritizeLcpImage.audit(artifacts, context);
expect(result).toEqual({
score: null,
notApplicable: true,
Expand All @@ -104,7 +106,7 @@ describe('Performance: preload-lcp audit', () => {
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl);
artifacts.TraceElements[0].type = 'text';
const context = {settings: {}, computedCache: new Map()};
const result = await PreloadLCPImage.audit(artifacts, context);
const result = await PrioritizeLcpImage.audit(artifacts, context);
expect(result).toEqual({
score: null,
notApplicable: true,
Expand All @@ -121,7 +123,7 @@ describe('Performance: preload-lcp audit', () => {
imagePaintEvent.args.data.DOMNodeId = 1729;

const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit(artifacts, context);
const results = await PrioritizeLcpImage.audit(artifacts, context);
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
Expand All @@ -132,7 +134,7 @@ describe('Performance: preload-lcp audit', () => {
networkRecords[3].isLinkPreload = true;
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit(artifacts, context);
const results = await PrioritizeLcpImage.audit(artifacts, context);
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
Expand All @@ -143,7 +145,7 @@ describe('Performance: preload-lcp audit', () => {
networkRecords[3].protocol = 'data';
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit(artifacts, context);
const results = await PrioritizeLcpImage.audit(artifacts, context);
expect(results.score).toEqual(1);
expect(results.details.overallSavingsMs).toEqual(0);
expect(results.details.items).toHaveLength(0);
Expand All @@ -153,7 +155,7 @@ describe('Performance: preload-lcp audit', () => {
const networkRecords = mockNetworkRecords();
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit(artifacts, context);
const results = await PrioritizeLcpImage.audit(artifacts, context);
expect(results.numericValue).toEqual(180);
expect(results.details.overallSavingsMs).toEqual(180);
expect(results.details.items[0].url).toEqual(imageUrl);
Expand All @@ -175,7 +177,7 @@ describe('Performance: preload-lcp audit', () => {
networkRecords[3].transferSize = 5 * 1000 * 1000;
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit(artifacts, context);
const results = await PrioritizeLcpImage.audit(artifacts, context);
expect(results.numericValue).toEqual(30);
expect(results.details.overallSavingsMs).toEqual(30);
expect(results.details.items[0].url).toEqual(imageUrl);
Expand All @@ -187,7 +189,7 @@ describe('Performance: preload-lcp audit', () => {
networkRecords[2].transferSize = 2 * 1000 * 1000;
const artifacts = mockArtifacts(networkRecords, mainDocumentNodeUrl);
const context = {settings: {}, computedCache: new Map()};
const results = await PreloadLCPImage.audit(artifacts, context);
const results = await PrioritizeLcpImage.audit(artifacts, context);
expect(results.numericValue).toEqual(30);
expect(results.details.overallSavingsMs).toEqual(30);
expect(results.details.items[0].url).toEqual(imageUrl);
Expand Down
Loading

0 comments on commit de6b53a

Please sign in to comment.