Skip to content
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

Merged
merged 4 commits into from
May 2, 2019

Conversation

patrickhulce
Copy link
Collaborator

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 :)

@patrickhulce patrickhulce changed the title core(runner): only pass requiredArtifacts core(runner): audits can only use requiredArtifacts May 1, 2019
@@ -325,7 +325,12 @@ class Runner {
...sharedAuditContext,
};

const product = await audit.audit(artifacts, auditContext);
const requiredArtifacts = audit.meta.requiredArtifacts
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol whoops

Copy link
Member

@brendankenny brendankenny left a 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) {
Copy link
Member

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
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah nice catch!

lighthouse-core/runner.js Show resolved Hide resolved
.reduce((requiredArtifacts, artifactName) => {
requiredArtifacts[artifactName] = artifacts[artifactName];
return requiredArtifacts;
}, /** @type {LH.Artifacts} */ ({}));
Copy link
Member

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...

Copy link
Collaborator Author

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 :)

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@brendankenny
Copy link
Member

ha, fascinating. The yarn smoke dbw failure is real (going from 6 console errors to 8). Turns out since CSSUsage was optional it wasn't running via the dbw config. Now that it does run, it appears to be causing re-requests of two of the 404ing stylesheets.

Is there an easy check we can add to css-usage.js or should we just bump the error count for now?

@patrickhulce
Copy link
Collaborator Author

Is there an easy check we can add to css-usage.js or should we just bump the error count for now?

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 👍

@brendankenny brendankenny merged commit 2826173 into master May 2, 2019
@brendankenny brendankenny deleted the only_pass_required_artifacts branch May 2, 2019 00:56
@paulirish paulirish mentioned this pull request May 2, 2019
67 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants