-
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
SEO - description audit #3227
Merged
Merged
SEO - description audit #3227
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c9d0c1b
SEO description audit - WIP
kdzwinel ce43b79
Add tests, fix audit, rename audit file
kdzwinel 9aa4cc2
Use CAPITALIZED_WITH_UNDERSCORES instead of CamelCase for a test cons…
kdzwinel dafe4ae
Extend defaultPass instead of creating a new one. Rename Description …
kdzwinel 969143e
Trim the description before checking length. Add debugString's.
kdzwinel e2302f0
Test if failing audits return a debugString.
kdzwinel 255196f
No debugString when tag is missing, better tests, trailing comma.
kdzwinel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license Copyright 2017 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 Description extends Audit { | ||
/** | ||
* @return {!AuditMeta} | ||
*/ | ||
static get meta() { | ||
return { | ||
category: 'Content Best Practices', | ||
name: 'meta-description', | ||
description: 'Document has a meta description', | ||
failureDescription: 'Document does not have a meta description', | ||
helpText: 'Meta descriptions may be included in search results to concisely summarize ' + | ||
'page content. Read more in the ' + | ||
'[Search Console Help page](https://support.google.com/webmasters/answer/35624?hl=en#1).', | ||
requiredArtifacts: ['MetaDescription'] | ||
}; | ||
} | ||
|
||
/** | ||
* @param {!Artifacts} artifacts | ||
* @return {!AuditResult} | ||
*/ | ||
static audit(artifacts) { | ||
if (artifacts.MetaDescription === null) { | ||
return { | ||
rawValue: false | ||
}; | ||
} | ||
|
||
if (artifacts.MetaDescription.trim().length === 0) { | ||
return { | ||
rawValue: false, | ||
debugString: 'Description text is empty.' | ||
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. 👍 Seems okay to keep this, as it's an unexpected case that'd otherwise be hard to debug. |
||
}; | ||
} | ||
|
||
return { | ||
rawValue: true | ||
}; | ||
} | ||
} | ||
|
||
module.exports = Description; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @license Copyright 2017 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 Gatherer = require('../gatherer'); | ||
|
||
class MetaDescription extends Gatherer { | ||
|
||
/** | ||
* @param {{driver: !Object}} options Run options | ||
* @return {!Promise<?string>} The value of the description meta's content attribute, or null | ||
*/ | ||
afterPass(options) { | ||
const driver = options.driver; | ||
|
||
return driver.querySelector('head meta[name="description"]') | ||
.then(node => node && node.getAttribute('content')); | ||
} | ||
} | ||
|
||
module.exports = MetaDescription; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @license Copyright 2017 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('../../../audits/seo/meta-description.js'); | ||
const assert = require('assert'); | ||
|
||
/* eslint-env mocha */ | ||
|
||
describe('SEO: description audit', () => { | ||
it('fails when HTML does not contain a description meta tag', () => { | ||
const auditResult = Audit.audit({ | ||
MetaDescription: null | ||
}); | ||
assert.equal(auditResult.rawValue, false); | ||
}); | ||
|
||
it('fails when HTML contains an empty description meta tag', () => { | ||
const auditResult = Audit.audit({ | ||
MetaDescription: '' | ||
}); | ||
assert.equal(auditResult.rawValue, false); | ||
assert.ok(auditResult.debugString.includes('empty'), auditResult.debugString); | ||
}); | ||
|
||
it('fails when description consists only of whitespace', () => { | ||
const auditResult = Audit.audit({ | ||
MetaDescription: ' ' | ||
}); | ||
assert.equal(auditResult.rawValue, false); | ||
assert.ok(auditResult.debugString.includes('empty'), auditResult.debugString); | ||
}); | ||
|
||
it('passes when a description text is provided', () => { | ||
return assert.equal(Audit.audit({ | ||
MetaDescription: 'description text' | ||
}).rawValue, true); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
lighthouse-core/test/gather/gatherers/seo/meta-description-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @license Copyright 2017 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'; | ||
|
||
/* eslint-env mocha */ | ||
|
||
const MetaDescriptionGather = require('../../../../gather/gatherers/seo/meta-description'); | ||
const assert = require('assert'); | ||
const EXAMPLE_DESCRIPTION = 'description text'; | ||
let metaDescriptionGather; | ||
|
||
describe('Meta description gatherer', () => { | ||
// Reset the Gatherer before each test. | ||
beforeEach(() => { | ||
metaDescriptionGather = new MetaDescriptionGather(); | ||
}); | ||
|
||
it('returns an artifact', () => { | ||
return metaDescriptionGather.afterPass({ | ||
driver: { | ||
querySelector() { | ||
return Promise.resolve({ | ||
getAttribute: () => EXAMPLE_DESCRIPTION | ||
}); | ||
} | ||
} | ||
}).then(artifact => { | ||
assert.equal(artifact, EXAMPLE_DESCRIPTION); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Meta question for the LH team.
category
here is referring to the title of the audit group, not to be confused with the top-level audit category, SEO, defined in the config file?https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/seo.js#L25-L27
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.
@rviscomi yeah the field here has an ambiguous name and is not used anywhere anymore 😆
I'm in favor of removing entirely now that we have real categories that control quite a bit of report building (just as cleanup work by the LH team in other PRs, it's a mandatory field currently).