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

Update to psi v5 #98

Merged
merged 15 commits into from
Sep 6, 2019
Merged

Update to psi v5 #98

merged 15 commits into from
Sep 6, 2019

Conversation

JuanMaRuiz
Copy link
Contributor

Relates to #97

- Updated README with new psi version
- Updated tests: renamed files, updated assertions
- Updated output to extract new data from psi API
- Changed response.json fixture with the new output from psi API
- Reverted npm test script
- Minor improvements
@sindresorhus
Copy link
Contributor

❯ psi https://addyosmani.com

--------------------------------------------------------

Summary

URL:          addyosmani.com
Strategy:     mobile
Performance:  98

Field Data



Lab Data

First Contentful Paint                     | 1.0 s
First CPU Idle                             | 1.9 s
First Meaningful Paint                     | 1.0 s
Max Potential First Input Delay            | 160 ms
Speed Index                                | 3.0 s
Time to Interactive                        | 1.9 s

Opportunities

Eliminate render-blocking resources        | 78ms
Properly size images                       | 150ms
Reduce server response times (TTFB)        | 349ms

--------------------------------------------------------

I noticed there's no Field Data.

And there's an inconsistency between 160 ms and 78ms.

lib/output.js Outdated

const rules = getRules(lighthouseResult.categories.performance.auditRefs, 'load-opportunities');

const oppRule = rules.filter(opportunityRule => {
Copy link
Contributor

Choose a reason for hiding this comment

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

oppRule is not a good variable name. Use opportunityRule.

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 are right! Modified

lib/output.js Outdated
return ruleDetails.overallSavingsMs !== undefined && ruleDetails.overallSavingsMs > 0 && ruleDetails.type === 'opportunity';
});

oppRule.forEach(rule => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a for-of loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better in that way. I didn't want to modify too much in this first PR.

lib/output.js Outdated

function getReporter(format) {
format = ['cli', 'json', 'tap'].indexOf(format) === -1 ? 'cli' : format;
return require(`./formats/${format}`);
const outputFormat = ['cli', 'json', 'tap'].indexOf(format) === -1 ? 'cli' : format;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use .includes() instead of .indexOf()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

- Use for...of
- Better constant name
@JuanMaRuiz
Copy link
Contributor Author

JuanMaRuiz commented Jun 3, 2019

❯ psi https://addyosmani.com

--------------------------------------------------------

Summary

URL:          addyosmani.com
Strategy:     mobile
Performance:  98

Field Data



Lab Data

First Contentful Paint                     | 1.0 s
First CPU Idle                             | 1.9 s
First Meaningful Paint                     | 1.0 s
Max Potential First Input Delay            | 160 ms
Speed Index                                | 3.0 s
Time to Interactive                        | 1.9 s

Opportunities

Eliminate render-blocking resources        | 78ms
Properly size images                       | 150ms
Reduce server response times (TTFB)        | 349ms

--------------------------------------------------------

I noticed there's no Field Data.

That's because there is nothing to show according to PageSpeed API. Maybe we could remove that part if there is no data or provide the same response

no-field-data

The message could be something like this:

output-for-no-result

And there's an inconsistency between 160 ms and 78ms.

That is because the API provides the displayValue so I don't need to use pretty-ms. Two approaches here:

  • Use the configuration option {verbose: true} from pretty-ms. We are going to have an inconsistency as well because verbose options will show 160 milliseconds instead of 160 ms
  • Remove whitespaces from displayValue string returned by the API.

What approach do you prefer?

@sindresorhus
Copy link
Contributor

The message could be something like this:

Looks good, but I would make it white and not yellow. It's not a warning. It's a notice.

Remove whitespaces from displayValue string returned by the API.

👍

- Added message when empty Field Data section
- Removed whitespace between number and metric on API results
@JuanMaRuiz
Copy link
Contributor Author

The message could be something like this:

Looks good, but I would make it white and not yellow. It's not a warning. It's a notice.

Remove whitespaces from displayValue string returned by the API.

👍

@JuanMaRuiz JuanMaRuiz closed this Jun 5, 2019
@JuanMaRuiz JuanMaRuiz reopened this Jun 5, 2019
@JuanMaRuiz
Copy link
Contributor Author

Hi @sindresorhus I think all requested changes are done.

Best regards.

@markusdosch
Copy link

Any chance that this gets merged? It looks like this pull request is ready 😊

@addyosmani
Copy link
Collaborator

Thank you for all of your work on this, @JuanMaRuiz and @sindresorhus for dedicating time to a review. We really appreciate it.

I would like to have one more set of eyes on the PR from the PageSpeed Insights team and we're going to do a quick pass of it shortly.

Copy link
Collaborator

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

Hi, I'm one of the developers from PSI. This PR looks good!

I have some minor nits, but this could land as-is and take on most of the feedback as follow-ups, since most are enhancements on top of this PR.

lib/output.js Outdated
const optimizedResourceURL = RESOURCE_URL + querystring.stringify({url: response.id, strategy: parameters.strategy});
const threshold = getThreshold(parameters.threshold);
const {lighthouseResult, loadingExperience, id} = response;
const optimizedResourceURL = `${RESOURCE_URL}${querystring.stringify({url: id, strategy: parameters.strategy})}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is being deprecated as well, I would remove optimizedResourceURL and the flag that controls it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

lib/output.js Outdated
threshold
));

if (parameters.optimized) {
console.log('\nHere are your optimized images:', humanizeUrl(optimizedResourceURL));
console.log(`\nHere are your optimized images: ${humanizeUrl(optimizedResourceURL)}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete this as well I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

'',
_.map(ruleSetResults.filter(x => x.value > 0), renderSection).join('\n'),
setTitle('Opportunities'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this section should be elided if Opportunities is empty, or have some control text like Field Data, something like "No opportunities provided."
image
^ this looks a little off

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree. Added message if no 'Opportunities' are provided.

lib/output.js Outdated
const sortOn = require('sort-on');
const humanizeUrl = require('humanize-url');
const prettyMs = require('pretty-ms');

const THRESHOLD = 70;
const RESOURCE_URL = 'https://developers.google.com/speed/pagespeed/insights/optimizeContents?';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

const error = new Error(`Threshold of ${threshold} not met with score of ${response.ruleGroups.SPEED.score}`);
const score = reversePercentage(lighthouseResult.categories.performance.score);
if (score < threshold) {
const error = new Error(`Threshold of ${threshold} not met with score of ${score}`);
error.noStack = true;
throw error;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can delete param.download as well, since this endpoint is EOL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -23,74 +23,102 @@ function overview(url, strategy, scores) {
});

ret.push({
label: 'Speed',
value: scores.SPEED.score
label: 'Performance',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is i18n'd in the report under lighthouseResult > categories > performance > title but that is some future gold plating.

lib/output.js Outdated
}

const reversePercentage = num => num * 100;
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL there is a word for this.

Suggested change
const reversePercentage = num => num * 100;
const convertToPercentum = num => num * 100;

Copy link
Contributor Author

@JuanMaRuiz JuanMaRuiz Sep 2, 2019

Choose a reason for hiding this comment

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

Great TIL that word as well. Modified

const {audits} = lighthouseResult;
ret.push({
label: audits[rule.id].title,
value: audits[rule.id].displayValue.replace(/\s/g, '')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Modifying LH display values can be dangerous since it's hard to confirm it looks good in all locales. But I think this is okay...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I change this?

lib/output.js Outdated Show resolved Hide resolved
statistics(response.pageStats),
ruleSetResults(response.formattedResults.ruleResults),
overview(humanizeUrl(id), parameters.strategy, lighthouseResult),
fieldData(loadingExperience.metrics),
Copy link
Collaborator

Choose a reason for hiding this comment

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

The Field Data here is only page level field data, if there is no page level data this field will fall back to origin level data. This makes no distinction between the two. Example:

  • This site has only Origin level data
    image
  • "Field Data" ~= origin in this case
    image

I suggest pulling from originLoadingExperience.metrics instead so that it is always origin data, or pull both and mark each section, one as "Field Data (page)" and one as "Field Data (origin)".

Copy link
Contributor Author

@JuanMaRuiz JuanMaRuiz Sep 2, 2019

Choose a reason for hiding this comment

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

I have tried to change loadingExperience by originLoadingExperience but it seems that originLoadingExperience.metrics is not always part of the response. What do you think it would be the best approach? Should I left loadingExperience or I should show both metrics as you recommend?

@JuanMaRuiz
Copy link
Contributor Author

Many thanks @exterkamp for your review. I'll check all your comments and I'll fix them.

Best regards.

@JuanMaRuiz
Copy link
Contributor Author

Hi @addyosmani, @sindresorhus and @exterkamp I think I have applied all the changes requested (except this one. Please, if you have any chance, could you please take a look again to this PR?

Many thanks.

Best regards

Copy link
Collaborator

@addyosmani addyosmani left a comment

Choose a reason for hiding this comment

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

LGTM

@addyosmani
Copy link
Collaborator

Thank you immensely for all of your work on the V5 update, @JuanMaRuiz. Updating has been a long time coming, and we couldn't have done this without all of your help.

After discussing the latest status in person with @exterkamp, we are going to go ahead with landing your PR. We appreciate you addressing the majority of feedback comments.

In terms of next-steps after landing this PR:

  • The PageSpeed Insights team (well, @exterkamp :P) has kindly offered to keep a closer eye on this package and maintaining API parity than I have since it was first put together. We will be transferring the repo from my personal account over to GoogleChromeLabs in the next week or two. @sindresorhus will of course retain his current privs on the repo too.
  • Once moved over, Shane is going to sanity check we're all good for a release and publish a new major version of psi to npm. We'll try (time willing) to get together some release notes as part of this.

Looking forward to this going out! Thanks everyone!

@addyosmani addyosmani merged commit 0c6c01f into master Sep 6, 2019
@addyosmani addyosmani deleted the feature-psi-v5 branch September 6, 2019 23:18
@JuanMaRuiz
Copy link
Contributor Author

Thank you @addyosmani for let me participate in this project. I'm very happy to help and to see this PR merged.

I'll keep an eye on this (or the GoogleChromeLabs project) and I'll try to help in future improvements. While I was working in this PR I saw several things that could be improved but, because they weren't related with this update, I decided not to add that changes.

Thanks to @exterkamp and @sindresorhus for their comments that improved the quality of this PR (code and API).

Best regards!

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.

None yet

5 participants