-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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(pwa): revamp and move short_name_length audit #4860
Changes from 9 commits
046847f
aeda793
4e6f65a
8a9b0b1
f422128
96a232e
c8d18fc
1078f69
b7fe9ff
2f7fe37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,17 @@ | |
*/ | ||
'use strict'; | ||
|
||
const Audit = require('./audit'); | ||
const MultiCheckAudit = require('./multi-check-audit'); | ||
|
||
class ManifestShortNameLength extends Audit { | ||
class ManifestShortNameLength extends MultiCheckAudit { | ||
/** | ||
* @return {LH.Audit.Meta} | ||
*/ | ||
static get meta() { | ||
return { | ||
id: 'manifest-short-name-length', | ||
title: 'Manifest\'s `short_name` won\'t be truncated when displayed on homescreen', | ||
failureTitle: 'Manifest\'s `short_name` will be truncated when displayed ' + | ||
'on homescreen', | ||
title: 'The `short_name` won\'t be truncated on the homescreen', | ||
failureTitle: 'The `short_name` will be truncated on the homescreen', | ||
description: 'Make your app\'s `short_name` fewer than 12 characters to ' + | ||
'ensure that it\'s not truncated on homescreens. [Learn ' + | ||
'more](https://developers.google.com/web/tools/lighthouse/audits/manifest-short_name-is-not-truncated).', | ||
|
@@ -26,28 +25,37 @@ class ManifestShortNameLength extends Audit { | |
|
||
/** | ||
* @param {LH.Artifacts} artifacts | ||
* @return {Promise<LH.Audit.Product>} | ||
* @return {Promise<{failures: Array<string>, manifestValues: LH.Artifacts.ManifestValues, notApplicable?: boolean}>} | ||
*/ | ||
static audit(artifacts) { | ||
static audit_(artifacts) { | ||
/** @type {Array<string>} */ | ||
const failures = []; | ||
/** @type {Array<string>} */ | ||
const warnings = []; | ||
|
||
return artifacts.requestManifestValues(artifacts.Manifest).then(manifestValues => { | ||
const result = {warnings, failures, manifestValues}; | ||
|
||
// If there's no valid manifest, this audit is not applicable | ||
if (manifestValues.isParseFailure) { | ||
return { | ||
rawValue: false, | ||
}; | ||
result.notApplicable = true; | ||
return result; | ||
} | ||
|
||
const shortNameCheck = manifestValues.allChecks.find(i => i.id === 'hasShortName'); | ||
const shortNameLengthCheck = manifestValues.allChecks.find(i => i.id === 'shortNameLength'); | ||
|
||
// If there's no short_name present, this audit is not applicable | ||
if (shortNameCheck && !shortNameCheck.passing) { | ||
result.notApplicable = true; | ||
return result; | ||
} | ||
|
||
const hasShortName = manifestValues.allChecks.find(i => i.id === 'hasShortName'); | ||
if (!hasShortName || !hasShortName.passing) { | ||
return { | ||
rawValue: false, | ||
explanation: 'No short_name found in manifest.', | ||
}; | ||
if (shortNameLengthCheck && !shortNameLengthCheck.passing) { | ||
failures.push(shortNameLengthCheck.failureText); | ||
} | ||
|
||
const isShortEnough = manifestValues.allChecks.find(i => i.id === 'shortNameLength'); | ||
return { | ||
rawValue: !!isShortEnough && isShortEnough.passing, | ||
}; | ||
return result; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no warnings and only one possible failure, so why not drop mulitcheckAudit and do like const manifestValues = await artifacts.requestManifestValues(artifacts.Manifest);
// If there's no valid manifest, this audit is not applicable
if (manifestValues.isParseFailure) {
return {
rawValue: true,
notApplicable: true,
};
}
const shortNameCheck = manifestValues.allChecks.find(i => i.id === 'hasShortName');
const shortNameLengthCheck = manifestValues.allChecks.find(i => i.id === 'shortNameLength');
// If there's no short_name present, this audit is not applicable
if (shortNameCheck && !shortNameCheck.passing) {
return {
rawValue: true,
notApplicable: true,
};
}
if (shortNameLengthCheck && !shortNameLengthCheck.passing) {
return {
rawValue: false,
explanation: `Failure: ${shortNameLengthCheck.failureText}.`,
};
}
return {
rawValue: true,
}; |
||
}); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ const icons = require('../../lib/icons'); | |
const PWA_DISPLAY_VALUES = ['minimal-ui', 'fullscreen', 'standalone']; | ||
|
||
// Historically, Chrome recommended 12 chars as the maximum short_name length to prevent truncation. | ||
// See #69 for more discussion & https://developer.chrome.com/apps/manifest/name#short_name | ||
// For more discussion, see https://github.com/GoogleChrome/lighthouse/issues/69 and https://developer.chrome.com/apps/manifest/name#short_name | ||
const SUGGESTED_SHORTNAME_LENGTH = 12; | ||
|
||
class ManifestValues extends ComputedArtifact { | ||
|
@@ -69,7 +69,9 @@ class ManifestValues extends ComputedArtifact { | |
}, | ||
{ | ||
id: 'shortNameLength', | ||
failureText: 'Manifest `short_name` will be truncated when displayed on the homescreen', | ||
failureText: `Manifest's \`short_name\` is too long (>${SUGGESTED_SHORTNAME_LENGTH} ` + | ||
`characters) to be displayed on a homescreen without truncation`, | ||
// Pass if there's no short_name. Don't want to report a non-existent string is too long | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this should fail if there is no |
||
validate: manifestValue => !!manifestValue.short_name.value && | ||
manifestValue.short_name.value.length <= SUGGESTED_SHORTNAME_LENGTH, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,29 +30,30 @@ describe('Manifest: short_name_length audit', () => { | |
artifacts.Manifest = null; | ||
|
||
return ManifestShortNameLengthAudit.audit(artifacts).then(result => { | ||
assert.strictEqual(result.rawValue, false); | ||
assert.strictEqual(result.explanation, undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update test description (doesn't fail) |
||
assert.strictEqual(result.rawValue, true); | ||
assert.strictEqual(result.notApplicable, true); | ||
}); | ||
}); | ||
|
||
it('fails when an empty manifest is present', () => { | ||
const artifacts = generateMockArtifacts(); | ||
artifacts.Manifest = manifestParser('{}', EXAMPLE_MANIFEST_URL, EXAMPLE_DOC_URL); | ||
return ManifestShortNameLengthAudit.audit(artifacts).then(result => { | ||
assert.equal(result.rawValue, false); | ||
assert.equal(result.explanation, 'No short_name found in manifest.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sames |
||
assert.strictEqual(result.rawValue, true); | ||
assert.strictEqual(result.notApplicable, true); | ||
}); | ||
}); | ||
|
||
it('fails when a manifest contains no short_name and too long name', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sames |
||
it('fails when a manifest contains no short_name', () => { | ||
const artifacts = generateMockArtifacts(); | ||
const manifestSrc = JSON.stringify({ | ||
name: 'i\'m much longer than the recommended size', | ||
}); | ||
artifacts.Manifest = manifestParser(manifestSrc, EXAMPLE_MANIFEST_URL, EXAMPLE_DOC_URL); | ||
return ManifestShortNameLengthAudit.audit(artifacts).then(result => { | ||
assert.equal(result.rawValue, false); | ||
assert.notEqual(result.explanation, undefined); | ||
assert.strictEqual(result.rawValue, true); | ||
assert.strictEqual(result.notApplicable, true); | ||
assert.equal(result.explanation, undefined); | ||
}); | ||
}); | ||
|
||
|
@@ -66,6 +67,8 @@ describe('Manifest: short_name_length audit', () => { | |
artifacts.Manifest = manifestParser(manifestSrc, EXAMPLE_MANIFEST_URL, EXAMPLE_DOC_URL); | ||
return ManifestShortNameLengthAudit.audit(artifacts).then(result => { | ||
assert.equal(result.rawValue, false); | ||
assert.ok(result.explanation.includes('without truncation'), result.explanation); | ||
assert.ok(!result.explanation.includes('Manifest does not have `short_name`')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete this line as it's not a possibility any longer? Want to assert not not applicable, though? |
||
}); | ||
}); | ||
|
||
|
@@ -77,6 +80,7 @@ describe('Manifest: short_name_length audit', () => { | |
artifacts.Manifest = manifestParser(manifestSrc, EXAMPLE_MANIFEST_URL, EXAMPLE_DOC_URL); | ||
return ManifestShortNameLengthAudit.audit(artifacts).then(result => { | ||
assert.equal(result.rawValue, true); | ||
assert.equal(result.explanation, undefined); | ||
}); | ||
}); | ||
/* eslint-enable camelcase */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await!