-
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
added short-name-length check #145
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* @license | ||
* Copyright 2016 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Audit = require('../audit'); | ||
|
||
class ManifestShortNameLength extends Audit { | ||
/** | ||
* @override | ||
*/ | ||
static get tags() { | ||
return ['Manifest']; | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
static get name() { | ||
return 'manifest-short-name-length'; | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
static get description() { | ||
return 'App short_name won\'t be truncated on the homescreen'; | ||
} | ||
|
||
/** | ||
* @param {!Artifacts} artifacts | ||
* @return {!AuditResult} | ||
*/ | ||
static audit(artifacts) { | ||
let isShortNameShortEnough = false; | ||
let debugString; | ||
const manifest = artifacts.manifest.value; | ||
const suggestedLength = 12; | ||
|
||
if (manifest && manifest.short_name && manifest.short_name.value) { | ||
// Historically, Chrome recommended 12 chars as the maximum length to prevent truncation. | ||
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. maybe put in a mention of #69 to track while we figure out the answer there 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. +1 lets link the issue as theres some valuable discussion. 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. Done |
||
// See #69 for more discussion. | ||
isShortNameShortEnough = (manifest.short_name.value.length <= suggestedLength); | ||
if (!isShortNameShortEnough) { | ||
debugString = `${suggestedLength} chars is the suggested maximum length`; | ||
} | ||
} | ||
|
||
return ManifestShortNameLength.generateAuditResult( | ||
isShortNameShortEnough, | ||
undefined, | ||
debugString | ||
); | ||
} | ||
} | ||
|
||
module.exports = ManifestShortNameLength; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
const Audit = require('../../../audits/manifest/short-name-length.js'); | ||
const assert = require('assert'); | ||
const manifestParser = require('../../../helpers/manifest-parser'); | ||
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. right now you're not using this manifestParser... but you should. It's not worth it to handcraft the post-parser objects to pass in: https://github.com/GoogleChrome/lighthouse/blob/master/test/helpers/icons.js#L57-L76 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. Done |
||
|
||
/* global describe, it*/ | ||
|
||
describe('Manifest: short_name_length audit', () => { | ||
it('fails when an empty manifest is present', () => { | ||
const manifest = manifestParser('{}'); | ||
console.info('got empty manifest', manifest); | ||
return assert.equal(Audit.audit({manifest}).value, false); | ||
}); | ||
|
||
// Need to disable camelcase check for dealing with short_name. | ||
/* eslint-disable camelcase */ | ||
it('fails when a manifest contains no short_name', () => { | ||
const manifestSrc = JSON.stringify({ | ||
short_name: undefined | ||
}); | ||
const manifest = manifestParser(manifestSrc); | ||
return assert.equal(Audit.audit({manifest}).value, false); | ||
}); | ||
|
||
it('fails when a manifest contains a long short_name', () => { | ||
const manifestSrc = JSON.stringify({ | ||
short_name: 'i\'m much longer than the recommended size' | ||
}); | ||
const manifest = manifestParser(manifestSrc); | ||
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. We should also verify the Debug string is attached here 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. Done |
||
const out = Audit.audit({manifest}); | ||
assert.equal(out.value, false); | ||
assert.notEqual(out.debugString, undefined); | ||
}); | ||
|
||
it('succeeds when a manifest contains a short_name', () => { | ||
const manifestSrc = JSON.stringify({ | ||
short_name: 'Lighthouse' | ||
}); | ||
const manifest = manifestParser(manifestSrc); | ||
return assert.equal(Audit.audit({manifest}).value, true); | ||
}); | ||
/* 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.
does the
0
weight mean this is just advisory?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.
seems like it. I think it's appropriate for this test. 👍
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.
yeah, I think that's great. I was actually all ready to say that I didn't think your score shouldn't be docked just because your name was a little long
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.
ack