-
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
SEO - description audit #3227
Changes from 5 commits
c9d0c1b
ce43b79
9aa4cc2
dafe4ae
969143e
e2302f0
255196f
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,52 @@ | ||||||||||||
/** | ||||||||||||
* @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, | ||||||||||||
debugString: 'Description meta tag is missing.' | ||||||||||||
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. Actually now that you've brought it up in the other issue, I think I might have a slight preference to put these in the 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.
agree about confusion between user vs system errors in 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. IMO lighthouse/lighthouse-core/closure/typedefs/AuditResult.js Lines 31 to 35 in fadaef9
@patrickhulce WDYT? Can we keep the 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. Yeah sgtm, I'm sort of off the reservation when it comes to my hopes for debugString anyway :) 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'll put the title and debugString in the order you'd see them in the report:
Given that the debugString duplicates so much, i think we should exclude it. |
||||||||||||
}; | ||||||||||||
} | ||||||||||||
|
||||||||||||
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,15 @@ | |
|
||
module.exports = { | ||
extends: 'lighthouse:default', | ||
passes: [{ | ||
passName: 'defaultPass', | ||
gatherers: [ | ||
'seo/meta-description', | ||
] | ||
}], | ||
audits: [ | ||
'seo/meta-description', | ||
], | ||
groups: { | ||
'seo-mobile': { | ||
title: 'Mobile Friendly', | ||
|
@@ -28,7 +37,8 @@ module.exports = { | |
description: 'These ensure your app is able to be understood by search engine crawlers.', | ||
audits: [ | ||
{id: 'meta-viewport', weight: 1, group: 'seo-mobile'}, | ||
{id: 'document-title', weight: 1, group: 'seo-content'} | ||
{id: 'document-title', weight: 1, group: 'seo-content'}, | ||
{id: 'meta-description', weight: 1, group: 'seo-content'} | ||
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. nit: go for the trailing comma here so future diffs will be cleaner 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 saw trailing comma being used here and there, but since there is no 100% consistency, I left it out. The cleaner diffs argument SGTM, maybe we should make eslint to check for that? 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. AFAIK there wasn't any effort to do trailing commas other than occasionally sneaking them in as we touched code but huge +1 to turning on the eslint rule :) 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've opened an issue for it: #3304 👍 |
||
] | ||
} | ||
} | ||
|
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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @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', () => { | ||
return assert.equal(Audit.audit({ | ||
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. it would be good to assert that the audit is also returning a 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. will do 👍 |
||
MetaDescription: null | ||
}).rawValue, false); | ||
}); | ||
|
||
it('fails when HTML contains an empty description meta tag', () => { | ||
return assert.equal(Audit.audit({ | ||
MetaDescription: '' | ||
}).rawValue, false); | ||
}); | ||
|
||
it('fails when description consists only of whitespace', () => { | ||
return assert.equal(Audit.audit({ | ||
MetaDescription: ' ' | ||
}).rawValue, false); | ||
}); | ||
|
||
it('passes when a description text is provided', () => { | ||
return assert.equal(Audit.audit({ | ||
MetaDescription: 'description text' | ||
}).rawValue, true); | ||
}); | ||
}); |
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); | ||
}); | ||
}); | ||
}); |
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).