core(computed-artifacts): disallow undefined properties #16397
Merged
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.
The type interface between audits/gatherers and computed artifacts is unsound: both audits and gatherers use the full
LH.Artifacts
type, even though both are actually limited by the runner. At some point I wanted to fix this, but for some unwritten reason the change was not merged.Recently in #16396 I struggled to add
SourceMaps
to a computed artifact used by many audits over multiple layers of our modules. Errors looked like "can't callfind
on undefined", and was many files removed from the audit file that was missing a declaration for "SourceMaps". What helped me make the change was tweaking how computed artifacts work:makeComputedArtifact
, disallow anyundefined
value given as properties of thedependencies
objectundefined
/ optional properties to instead be nullableThis allows the error to be generated right next to the improper usage. It also forces all callers, including tests, to consider every portion of the dependencies object - this is a little cumbersome but I think is clearly a benefit in that it makes for more accurate tests.
I decided to only throw an error in
makeComputedArtifact
ifisUnderTest
is true - in production this will simply log an error message. This is to allow any thing this PR may have missed, but was still otherwise OK, from producing false errors.