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

new_audit(pwa): maskable icon audit #10370

Merged
merged 15 commits into from
Feb 26, 2020
Merged

new_audit(pwa): maskable icon audit #10370

merged 15 commits into from
Feb 26, 2020

Conversation

Beytoven
Copy link
Contributor

@Beytoven Beytoven commented Feb 21, 2020

We want to add a new audit that checks whether a PWA's manifest declares at least one icon as maskable.

Screen Shot 2020-02-21 at 3 28 08 PM

image

fixes #10197

@Beytoven Beytoven requested a review from a team as a code owner February 21, 2020 23:49
@Beytoven Beytoven requested review from patrickhulce and removed request for a team February 21, 2020 23:49
@paulirish paulirish changed the title new_audit(PWA): maskable icon audit new_audit(PWA): maskable icon audi Feb 22, 2020
Copy link
Collaborator

@patrickhulce patrickhulce left a 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! 🎉

lighthouse-core/audits/maskable-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/maskable-icon.js Outdated Show resolved Hide resolved
lighthouse-core/audits/maskable-icon.js Show resolved Hide resolved
lighthouse-core/lib/icons.js Outdated Show resolved Hide resolved
lighthouse-core/lib/icons.js Show resolved Hide resolved
@@ -241,6 +241,7 @@ function parseIcon(raw, manifestUrl) {
}

const type = parseString(raw.type, true);
const purpose = parseString(raw.purpose, true);
Copy link
Collaborator

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.",
Copy link
Collaborator

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

lighthouse-core/config/default-config.js Show resolved Hide resolved
artifacts.WebAppManifest = null;

const auditResult = await MaskableIconAudit.audit(artifacts, context);
assert.equal(auditResult.score, 0);
Copy link
Collaborator

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 saying Expected 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 with assert

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

Copy link
Contributor Author

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>
@paulirish paulirish changed the title new_audit(PWA): maskable icon audi new_audit(PWA): maskable icon audit Feb 24, 2020
@paulirish paulirish changed the title new_audit(PWA): maskable icon audit new_audit(PWA): maskable icon audi Feb 25, 2020
@paulirish paulirish changed the title new_audit(PWA): maskable icon audi new_audit(pwa): maskable icon audit Feb 25, 2020
Copy link
Collaborator

@patrickhulce patrickhulce left a 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?

lighthouse-core/lib/manifest-parser.js Outdated Show resolved Hide resolved
lighthouse-core/lib/manifest-parser.js Show resolved Hide resolved
const purpose = {
raw: raw.purpose,
/** @type {string[]} */
value: [],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
value: [],
value: ['any'],

artifacts.WebAppManifest = null;

const auditResult = await MaskableIconAudit.audit(artifacts, context);
expect(auditResult.score).toEqual(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

expect 😍

lighthouse-core/test/lib/icons-test.js Outdated Show resolved Hide resolved
@paulirish
Copy link
Member

do we happen to know of sites that use a maskable icon correctly we can verify in the wild?

https://squoosh.app is the primary one i know about.

Co-Authored-By: Patrick Hulce <patrick.hulce@gmail.com>
@Beytoven
Copy link
Contributor Author

do we happen to know of sites that use a maskable icon correctly we can verify in the wild?

https://squoosh.app is the primary one i know about.

I've verified it's working using the PWA mentioned by Paul above. Added a screenshot to the PR for additional verification. @patrickhulce

Copy link
Collaborator

@patrickhulce patrickhulce left a 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[]} */
Copy link
Collaborator

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

lighthouse-core/test/lib/icons-test.js Outdated Show resolved Hide resolved
Co-Authored-By: Patrick Hulce <patrick.hulce@gmail.com>
@paulirish
Copy link
Member

😷 🎨 🎉

@mathiasbynens
Copy link
Member

Exciting to see this land 🎉 Nice work @Beytoven!

do we happen to know of sites that use a maskable icon correctly we can verify in the wild?

v8.dev has one as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PWA audit: warn when no maskable icons are declared
7 participants