-
Notifications
You must be signed in to change notification settings - Fork 126
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
Update to psi v5 #98
Conversation
- 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
I noticed there's no And there's an inconsistency between |
lib/output.js
Outdated
|
||
const rules = getRules(lighthouseResult.categories.performance.auditRefs, 'load-opportunities'); | ||
|
||
const oppRule = rules.filter(opportunityRule => { |
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.
oppRule
is not a good variable name. Use opportunityRule
.
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 are right! Modified
lib/output.js
Outdated
return ruleDetails.overallSavingsMs !== undefined && ruleDetails.overallSavingsMs > 0 && ruleDetails.type === 'opportunity'; | ||
}); | ||
|
||
oppRule.forEach(rule => { |
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.
Use a for-of
loop.
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.
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; |
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 can use .includes()
instead of .indexOf()
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.
Done!
- Use for...of - Better constant name
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 The message could be something like this:
That is because the API provides the
What approach do you prefer? |
Looks good, but I would make it white and not yellow. It's not a warning. It's a notice.
👍 |
- Added message when empty Field Data section - Removed whitespace between number and metric on API results
|
Hi @sindresorhus I think all requested changes are done. Best regards. |
Any chance that this gets merged? It looks like this pull request is ready 😊 |
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. |
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.
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})}`; |
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 is being deprecated as well, I would remove optimizedResourceURL
and the flag that controls it.
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.
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)}`); |
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.
Delete this as well I think.
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.
Done
'', | ||
_.map(ruleSetResults.filter(x => x.value > 0), renderSection).join('\n'), | ||
setTitle('Opportunities'), |
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.
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 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?'; |
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.
Remove.
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.
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; | ||
} |
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.
Can delete param.download as well, since this endpoint is EOL.
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.
Done
@@ -23,74 +23,102 @@ function overview(url, strategy, scores) { | |||
}); | |||
|
|||
ret.push({ | |||
label: 'Speed', | |||
value: scores.SPEED.score | |||
label: 'Performance', |
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 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; |
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.
TIL there is a word for this.
const reversePercentage = num => num * 100; | |
const convertToPercentum = num => num * 100; |
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.
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, '') |
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.
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...
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.
Should I change this?
statistics(response.pageStats), | ||
ruleSetResults(response.formattedResults.ruleResults), | ||
overview(humanizeUrl(id), parameters.strategy, lighthouseResult), | ||
fieldData(loadingExperience.metrics), |
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.
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:
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)".
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 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?
Many thanks @exterkamp for your review. I'll check all your comments and I'll fix them. Best regards. |
- Removed deprecated optimized and download options from output
… show proper data
Co-Authored-By: Shane Exterkamp <shaneexterkamp5@gmail.com>
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 |
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
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:
Looking forward to this going out! Thanks everyone! |
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! |
Relates to #97