-
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
new_audit(pwa): maskable icon audit #10370
Conversation
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 looks great @Beytoven! great job covering all our bases with the tests, love it! 🎉
@@ -241,6 +241,7 @@ function parseIcon(raw, manifestUrl) { | |||
} | |||
|
|||
const type = parseString(raw.type, true); | |||
const purpose = parseString(raw.purpose, true); |
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.
looks like the default is "any"
if we want to stick to the spec
"description": "A maskable icon ensures that the icon fills the entire shape when installing the app on a device. [Learn more](https://web.dev/maskable-icon/).", | ||
"score": 0, | ||
"scoreDisplayMode": "binary", | ||
"explanation": "Failures: No manifest was fetched.", |
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.
looks like this used to a multicheck audit so you'll probably need to yarn update:sample-json
again :)
artifacts.WebAppManifest = null; | ||
|
||
const auditResult = await MaskableIconAudit.audit(artifacts, context); | ||
assert.equal(auditResult.score, 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.
🚨 totally optional personal appeal below 🚨
since this is a brand new test file I'll attempt to pitch you on why new tests should use expect instead of assert :)
while it has pretty much no impact on this particular file, expect
gives us some nice powers over assert, namely
- partial matching
expect({foo: 1, ...giantListOfOtherProperties}).toMatchObject({foo: 1})
will pass and on failure still print out the rest of the object for better debugging - better array length debugging
expect(arr).toHaveLength(5)
will print the contents of the array on failure for debugging instead of just sayingExpected 5 got 4
- snapshot testing
expect(someObject).toMatchInlineSnapshot()
is super handy for tests where we don't necessarily have an absolute correct answer but we want to be aware when anything affects the behavior (think lantern metrics, complicated byte or time savings estimation logic, etc) jest automatically manages these golden file expectations inline and can update them with the-u
flag to jest - mock assertions
expect(jest.fn()).toHaveBeenCalledWith('foo')
, much easier to read and grok than the manual mock functions we have crafted elsewhere withassert
on the whole, most of the codebase is still assert
and when adding individual tests that don't benefit from expect
to thsoe files, totally expected to follow the surrounding style, but in new places where we might want to reap the benefits of expect I strongly support the use expect
and that's my spiel, feel free to decide for yourself moving forward when to use what appropriately :)
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.
You've sold me! Made the switch.
Co-Authored-By: Patrick Hulce <patrick.hulce@gmail.com>
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 work!! pretty much there just a last spec-nit change
do we happen to know of sites that use a maskable icon correctly we can verify in the wild?
const purpose = { | ||
raw: raw.purpose, | ||
/** @type {string[]} */ | ||
value: [], |
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.
value: [], | |
value: ['any'], |
artifacts.WebAppManifest = null; | ||
|
||
const auditResult = await MaskableIconAudit.audit(artifacts, context); | ||
expect(auditResult.score).toEqual(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.
expect
😍
https://squoosh.app is the primary one i know about. |
Co-Authored-By: Patrick Hulce <patrick.hulce@gmail.com>
I've verified it's working using the PWA mentioned by Paul above. Added a screenshot to the PR for additional verification. @patrickhulce |
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, nicely done @Beytoven! 🎉
const parsedPurpose = parseString(raw.purpose); | ||
const purpose = { | ||
raw: raw.purpose, | ||
/** @type {string[]} */ |
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 don't think you need this now that it's ['any']
instead of []
but I could be wrong :)
Co-Authored-By: Patrick Hulce <patrick.hulce@gmail.com>
😷 🎨 🎉 |
Exciting to see this land 🎉 Nice work @Beytoven!
v8.dev has one as well. |
We want to add a new audit that checks whether a PWA's manifest declares at least one icon as maskable.
fixes #10197