-
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(runner): audits can only use requiredArtifacts #8760
Conversation
@@ -325,7 +325,12 @@ class Runner { | |||
...sharedAuditContext, | |||
}; | |||
|
|||
const product = await audit.audit(artifacts, auditContext); | |||
const requiredArtifacts = audit.meta.requiredArtifacts |
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.
the magic
* @return {Promise<ViewportMetaResult>} | ||
*/ | ||
static async compute_({MetaElements}) { | ||
static async compute_(MetaElements) { |
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.
a necessary refactor to ensure that they're still cached, also this seems like a bad idea to cache on the entire artifacts object 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.
lol whoops
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 really like this!
Can you also add a test for it in runner-test.js
? There's already a few in there around artifact handling it could go with (e.g. "Bad required artifact handling", though this wouldn't be the bad case, I guess)
* @return {Promise<ViewportMetaResult>} | ||
*/ | ||
static async compute_({MetaElements}) { | ||
static async compute_(MetaElements) { |
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.
lol whoops
@@ -73,7 +73,7 @@ class RenderBlockingResources extends Audit { | |||
// This audit also looks at CSSUsage but has a graceful fallback if it failed, so do not mark |
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.
do you want to change anything about CSSUsage
for this audit, since after this PR it won't ever see it unless we get around to optionalArtifacts?
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.
oh yeah nice catch!
.reduce((requiredArtifacts, artifactName) => { | ||
requiredArtifacts[artifactName] = artifacts[artifactName]; | ||
return requiredArtifacts; | ||
}, /** @type {LH.Artifacts} */ ({})); |
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.
this is unfortunate, but fine enough. Maybe add a line about the masquerading type to the above comment as well?
I was hoping at one point that we could type the artifacts
input of an audit based on its declared requiredArtifacts
, but it would require not having Array<string>
for the requiredArtifacts
type, was finicky because it was nested on the meta
getter, and didn't gain us all that much, but maybe in some future version of typescript...
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 thought about it for about 5 seconds before thinking there was no way it was going to be usable 😆
hopefully one day typescript will let you work your magic 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.
LGTM!
ha, fascinating. The Is there an easy check we can add to |
We can add a check but it's non trivial and I'm not sure it's worth it :) I'll bump the error count for now 👍 |
Summary
One more breaking change I want to get in we discussed in the meeting that I misunderstood and thought was already on someone's plate :)
an audit can only use its
requiredArtifacts
With plugins it feels like folks aren't going to remember to use
requiredArtifacts
and if we ever want to enforce it, seems like we need to do it now.This also fixes the dozen or so audits that were cheating :)