-
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
Conversation
lighthouse-core/config/seo.js
Outdated
@@ -7,6 +7,15 @@ | |||
|
|||
module.exports = { | |||
extends: 'lighthouse:default', | |||
passes: [{ | |||
passName: 'seoPass', |
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.
patrick says you can just passName: 'defaultPass'
and get this gather merged into that one.
so no need for an extra pass
*/ | ||
static audit(artifacts) { | ||
return { | ||
rawValue: (artifacts.Description !== null && artifacts.Description.length > 0) |
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.
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.
- trim sgtm
- debugString for those cases would be nice
- yes this seems like a bug :) there's some magic that happens if the rawValue is a number to auto-populate the score but even if that's producing something weird the UI should still be consistent.
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.
Thanks for help! Regarding no.3 - should I create an issue for it?
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.
Inconsistency does look like a bug. In the meantime, should be able to set scoringMode: Audit.SCORING_MODES.NUMERIC
in the meta information (otherwise everything other than 100 is interpreted as failing)
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.
@brendankenny thanks! For this audit rawValue is a boolean so we are fine, but I'll keep your advice in mind for the next ones.
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.
If the meta description exists but is invalid, I'd also recommend including the markup in the debugString. For example:
Description text is empty: `<meta name="description" content=" ">`
It'll be helpful for developers to know where to look to fix the issue.
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 I think that's a good idea, but I wonder if it won't be confusing to show <meta name="description" content=" ">
while the actual tag on page may look totally different (e.g. <META YADA="yada" CONTENT=" " name="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.
nice! very clean 👍
lighthouse-core/config/seo.js
Outdated
@@ -7,6 +7,15 @@ | |||
|
|||
module.exports = { | |||
extends: 'lighthouse:default', | |||
passes: [{ | |||
passName: 'seoPass', |
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.
if you set passName
to 'defaultPass' then the gatherer should just be added to the list to run, if not it's a bug and I can look into it :)
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: ['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.
Description
is rather generic, what about MetaDescription
or start namespacing with SEODescription
if there are going to be many more seo specific ones?
…artifact to MetaArtifact (and update gatherer file name accordingly)
@paulirish @patrickhulce thank you for your comments!
Interestingly, the problem goes away if it's not running last:
🤔
|
Yeah the debug timestamps are confusing to read, the |
Good job |
thanks for explanation, it makes sense (although I'll have to agree that it's not very intuitive) I've added description trimming and debugStrings. PTAL |
*/ | ||
static get meta() { | ||
return { | ||
category: 'Content Best Practices', |
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).
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.
LGTM!
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 comment
The 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 displayValue
and keep debugString
for errors like the gatherer failing (which is handled automatically)
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.
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 displayValue and keep debugString for errors like the gatherer failing (which is handled automatically)
agree about confusion between user vs system errors in debugString
, but don't we still want the red string for failure here? (We still use the guidance "Optional error string for helping the user figure out why they failed here." in our docs)
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.
IMO debugString
is more readable and, as @brendankenny mentioned, in this case it matches the description from the docs:
lighthouse/lighthouse-core/closure/typedefs/AuditResult.js
Lines 31 to 35 in fadaef9
/** | |
* Optional error string for helping the user figure out why they failed here. | |
* @type {(string|undefined)} | |
*/ | |
AuditResult.prototype.debugString; |
@patrickhulce WDYT? Can we keep the debugString
here?
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 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 comment
The 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:
Document does not have a meta description
Description meta tag is missing
Given that the debugString duplicates so much, i think we should exclude it.
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.
Gatherer unit tests are often inadequate as they tend to just be a test of how accurate the test mock is. We should set up integration tests for the incoming SEO audits so we can assert that the full gather-to-audit process is working.
It could be added to an existing test suite, but setting up a new one that uses the SEO config may be the best first step (unless anyone feels otherwise).
I think it's ok to not handle it in this PR so it stays nicely focused, but we should get one going ASAP
|
||
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 comment
The 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 debugString
(or a displayValue
, depending on how the comment above shakes out :)
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.
will do 👍
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.
just last two nits and I think I'm good
lighthouse-core/config/seo.js
Outdated
@@ -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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened an issue for it: #3304 👍
MetaDescription: null | ||
}); | ||
assert.equal(auditResult.rawValue, false); | ||
assert.ok(auditResult.debugString); |
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.
it would probably be (slightly) better to check which string is getting returned as the debugString
since there's two different cases (could go for an exact string match or a debugString.includes()
on 'empty'
and 'missing'
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.
+1 to a quick includes check
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 comment
The 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:
Document does not have a meta description
Description meta tag is missing
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 comment
The 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.
I removed the 'tag missing' PTAL |
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.
woohoo! Let's land
Closes #3175