[go: nahoru, domu]

Skip to content

Commit

Permalink
core(viewport): add INP savings (#15071)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Jun 15, 2023
1 parent 0a32e6c commit be747ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/audits/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,26 @@ class Viewport extends Audit {
static async audit(artifacts, context) {
const viewportMeta = await ViewportMeta.request(artifacts.MetaElements, context);

let inpSavings = 300;
if (!viewportMeta.hasViewportTag) {
return {
score: 0,
explanation: str_(UIStrings.explanationNoTag),
metricSavings: {
INP: inpSavings,
},
};
}

if (viewportMeta.isMobileOptimized) {
inpSavings = 0;
}

return {
score: Number(viewportMeta.isMobileOptimized),
metricSavings: {
INP: inpSavings,
},
warnings: viewportMeta.parserWarnings,
};
}
Expand Down
3 changes: 3 additions & 0 deletions core/test/audits/viewport-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ describe('Mobile-friendly: viewport audit', () => {
}, fakeContext);
assert.equal(auditResult.score, 0);
expect(auditResult.explanation).toBeDisplayString('No `<meta name="viewport">` tag found');
expect(auditResult.metricSavings).toEqual({INP: 300});
});

it('fails when HTML contains a non-mobile friendly viewport meta tag', async () => {
const viewport = 'maximum-scale=1';
const auditResult = await Audit.audit({MetaElements: makeMetaElements(viewport)}, fakeContext);
assert.equal(auditResult.score, 0);
assert.equal(auditResult.warnings[0], undefined);
expect(auditResult.metricSavings).toEqual({INP: 300});
});

it('passes when a valid viewport is provided', async () => {
Expand All @@ -33,5 +35,6 @@ describe('Mobile-friendly: viewport audit', () => {
MetaElements: makeMetaElements(viewport),
}, fakeContext);
assert.equal(auditResult.score, 1);
expect(auditResult.metricSavings).toEqual({INP: 0});
});
});

0 comments on commit be747ee

Please sign in to comment.