-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
core(lhr): make reportCategories shallow; move audit scores to AuditResultJSON #4711
Conversation
5d94217
to
e24e3c7
Compare
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! let's keep this chain amovin' we've got lots of #4333 to land :D
lighthouse-core/runner.js
Outdated
if (opts.config.categories) { | ||
report = Runner._scoreAndCategorize(opts, resultsById); | ||
Runner._scoreAndCategorize(opts, resultsById); | ||
// COMPAT: after dropping Node 6, upgrade to use Object.values |
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.
does this mean we can do it now? :)
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.
do it!
lighthouse-core/scoring.js
Outdated
const category = config.categories[categoryId]; | ||
category.id = categoryId; | ||
|
||
const audits = category.audits.map(audit => { | ||
category.audits.forEach(audit => { | ||
const result = resultsByAuditId[audit.id]; | ||
// Cast to number to catch `null` and undefined when audits 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.
should all of these line just be moved into audit.js
then to keep all the score mapping in the same place?
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.
more a comment for #4690 I suppose
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.
Aye. It actually already happens in that PR: https://github.com/GoogleChrome/lighthouse/pull/4690/files#diff-488f5da33160a651526463bdb951e5deL31
smokehouse failures? |
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 looking good to me so far. As discussed, we'll want to smoosh the audit results into a copy of the LHR so the canonical one still exists untouched.
something for the future: as we add more typechecking, we may want to split AuditJSON
to a version with result
(only used inside the report renderer) and a version without (used everywhere else) so that we can more easily reason about which we have at some point in time and so we don’t have to put in a bunch of checks to keep tsc happy :)
lighthouse-core/runner.js
Outdated
if (opts.config.categories) { | ||
report = Runner._scoreAndCategorize(opts, resultsById); | ||
Runner._scoreAndCategorize(opts, resultsById); | ||
// COMPAT: after dropping Node 6, upgrade to use Object.values |
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.
do it!
Done. added a test.
YESSSSSSS. So want this. Here was my typechecking spike, validating the outgoing LHR against some real types. Works! 95e19a5...typechecking This and #4690 are updated and ready |
89c48f7
to
fddb987
Compare
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.
let's get this show on the 🚗 💨
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. Just the merge issue and two questions remaining 🌊➡️🛁
@@ -155,24 +157,39 @@ class ReportRenderer { | |||
perfCategoryRenderer.setTemplateContext(this._templateContext); | |||
|
|||
const categories = reportSection.appendChild(this._dom.createElement('div', 'lh-categories')); | |||
|
|||
ReportRenderer.smooshAuditResultsIntoCategories(report.audits, report.reportCategories); |
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.
does this make more sense up in renderReport
before passing into _renderReport
? Then internally it'll always be the smooshed version and we won't have to remember not to use reportCategories
above this line
* result: (ReportRenderer.AuditResultJSON|undefined) | ||
* }} | ||
*/ | ||
ReportRenderer.AuditJSON; // eslint-disable-line no-unused-expressions |
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.
defined below (merge conflict, I think)
@@ -108,8 +109,7 @@ class Runner { | |||
audits: resultsById, | |||
artifacts: runResults.artifacts, | |||
runtimeConfig: Runner.getRuntimeConfig(opts.flags), | |||
score: report ? report.score : 0, | |||
reportCategories: report ? report.categories : [], | |||
reportCategories: categories, |
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.
before this defaulted to an empty array. Will it cause problems anywhere as undefined
(and removed from the JSON) instead?
* @param {!Object<string, {score: ?number|boolean|undefined, notApplicable: boolean, informative: boolean}>} resultsByAuditId | ||
* @return {{score: number, categories: !Array<{audits: !Array<{score: number, result: !Object}>}>}} | ||
*/ | ||
static scoreAllCategories(config, resultsByAuditId) { | ||
const categories = Object.keys(config.categories).map(categoryId => { | ||
const category = config.categories[categoryId]; | ||
for (const [categoryId, category] of Object.entries(config.categories)) { |
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.
🎉
merge when green. |
f0cb8e6
to
b4ac5f0
Compare
Changes
reportCategories
no longer contains real auditResults (aka de-dupe all audit results from ☂️ 👣 Things to fix on next breaking change #4333).score
prop. Eg:reportCategories.performance.score
reportCategories.performance['audit-name']
(which now just holdsweight
andgroup
) over toaudits['audit-name']
LHR.score
, the overallScoreThis is a chain of PRs. Landing order is... 1st:
newdetails
(#4616). 2nd:shallowCategories
(#4711). 3rd:scoring2.0
(#4690)ref #4614
fixes #1999