Skip to content

Conversation

@connorjclark
Copy link
Collaborator

Split off from #9193

This introduces a way to call PSI from the viewer:

/?url=https://www.example.com&categories=seo,pwa

Had to update puppeteer because the version we had didn't work with request interception on newer Chrome.

Copy link
Contributor

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

at a high level:

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

can you add an example localhost:8000?url=... URL in the readme just for convenience

Copy link
Contributor

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

viewer code looking good, thanks for sticking with this review process.

Comments mostly on the tests

LH_CURRENT_VERSION: string;
}

interface PSIParams {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move into psi-api.js?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Defining it in jsdoc:

/**
 * @typedef PSIParams
 * @property {string} url
 * @property {string[]=} category
 * @property {string=} locale
 * @property {string=} strategy
 * @property {string=} utm_source
 */

results in:

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactor that loop (do type checking instead of checking the name of the property)? Or don't do this change? Or some way to define the type in jsdoc and keep the same behavior?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, ha, that's weird. Somehow the one in d.ts is less strict (setting value to any) than doing it in a typedef (setting value to string | string[] | undefined)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

expect(interceptedUrl.searchParams.getAll('category')).toEqual([
'seo',
'pwa',
]);
Copy link
Contributor

Choose a reason for hiding this comment

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

for these, maybe cleaner to do expect([... interceptedUrl.searchParams.entries()]).toEqual([...])?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think these query params should be tested one at a time.

Copy link
Contributor

Choose a reason for hiding this comment

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

for these, maybe cleaner to do expect([... interceptedUrl.searchParams.entries()]).toEqual([...])?

I think these query params should be tested one at a time.

that's fine, I guess what I was really suggesting is that we should be testing all of them (especially strategy since it gets a default? and probably key, though the exact value matters less) and that form was just a way to cut down on the expect(...).toEqual(...) verboseness

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK - done

Copy link
Contributor

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

some last nits but otherwise...let's do this
⛵️📎⛳️

// These values aren't set by default.
locale: null,
utm_source: null,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like an elaborate way not to write

expect([...interceptedUrl.searchParams]).toEqual([
  ['url', 'https://www.example.com'],
  ['strategy', 'mobile'],
  // Order in the api call is important to PSI!
  ['category', 'performance'],
  ['category', 'accessibility'],
  ['category', 'seo'],
  ['category', 'best-practices'],
  ['category', 'pwa'],
  ['key', 'AIzaSyAjcDRNN9CX9dCazhqI4lGR7yyQbkd_oYE'],
  // `locale` and `utm_source` aren't set by default.
]);

but either way works :P

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 array mumbo jumbo doesn't make for very good error message when the assertion fails.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants