-
Notifications
You must be signed in to change notification settings - Fork 9.6k
report: reuse generalized clumping for perf category #9288
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
Changes from 3 commits
1e86d5e
151fc98
27c3215
3d2f41b
9eb5b08
670624b
d72e53b
8f93171
865cbd4
ae3c77f
c934c4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -413,6 +413,22 @@ class CategoryRenderer { | |||||
| this.createPermalinkSpan(element, category.id); | ||||||
| element.appendChild(this.renderCategoryHeader(category, groupDefinitions)); | ||||||
|
|
||||||
| const clumpElems = this._splitAndRenderClumps(category.auditRefs, groupDefinitions, | ||||||
| category.manualDescription); | ||||||
| element.append(...clumpElems); | ||||||
| return element; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * | ||||||
| * @param {LH.ReportResult.AuditRef[]} auditRefs | ||||||
| * @param {Object<string, LH.Result.ReportGroup>} [groupDefinitions] | ||||||
paulirish marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| * @param {LH.Result.Category.manualDescription} [manualDescription] | ||||||
paulirish marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| * @return {Element[]} | ||||||
paulirish marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| */ | ||||||
| _splitAndRenderClumps(auditRefs, groupDefinitions = {}, manualDescription) { | ||||||
|
||||||
| _splitAndRenderClumps(auditRefs, groupDefinitions = {}, manualDescription) { | |
| renderClumps(auditRefs, groupDefinitions, manualDescription) { |
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.
also should move the really good ascii diagram + description to this method as this is the one actually doing it now
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,7 +156,7 @@ class PerformanceCategoryRenderer extends CategoryRenderer { | |
|
|
||
| // Filmstrip | ||
| const timelineEl = this.dom.createChildOf(element, 'div', 'lh-filmstrip-container'); | ||
| const thumbnailAudit = category.auditRefs.find(audit => audit.id === 'screenshot-thumbnails'); | ||
| const thumbnailAudit = category.auditRefs.find(audit => audit.group === 'filmstrip'); | ||
|
||
| const thumbnailResult = thumbnailAudit && thumbnailAudit.result; | ||
| if (thumbnailResult && thumbnailResult.details) { | ||
| timelineEl.id = thumbnailResult.id; | ||
|
|
@@ -165,7 +165,7 @@ class PerformanceCategoryRenderer extends CategoryRenderer { | |
| } | ||
|
|
||
| // Budgets | ||
| const budgetAudit = category.auditRefs.find(audit => audit.id === 'performance-budget'); | ||
| const budgetAudit = category.auditRefs.find(audit => audit.group === 'budgets'); | ||
| if (budgetAudit && budgetAudit.result.details) { | ||
| const table = this.detailsRenderer.render(budgetAudit.result.details); | ||
| if (table) { | ||
|
|
@@ -220,19 +220,14 @@ class PerformanceCategoryRenderer extends CategoryRenderer { | |
| element.appendChild(groupEl); | ||
| } | ||
|
|
||
| // Passed audits | ||
| const passedAudits = category.auditRefs | ||
| .filter(audit => (audit.group === 'load-opportunities' || audit.group === 'diagnostics') && | ||
| Util.showAsPassed(audit.result)); | ||
| // Everything else (passed, passed with warnings, n/a) | ||
| const renderedAudits = [...metricAudits, thumbnailAudit, budgetAudit, ...opportunityAudits, | ||
| ...diagnosticAudits]; | ||
| const unrenderedAudits = category.auditRefs.filter(ref => !renderedAudits.includes(ref)); | ||
| const remainingAudits = unrenderedAudits.filter(ref => !!ref.group); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems like it'll be easy to forget to add things to the What if we switched how we do the non-rendered audits and gave them an explicit group ( It would reduce the mystery of how the audits that don't show up in the html report work and let this check just be whatever hasn't been rendered yet and isn't in that group.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this sounds good. it means every auditRef needs a group. but that works for me. the tricky thing is but once that's cleaned up it makes sense to do that policy change. |
||
|
|
||
| if (!passedAudits.length) return element; | ||
|
|
||
| const clumpOpts = { | ||
| auditRefs: passedAudits, | ||
| groupDefinitions: groups, | ||
| }; | ||
| const passedElem = this.renderClump('passed', clumpOpts); | ||
| element.appendChild(passedElem); | ||
| const clumpElems = this._splitAndRenderClumps(remainingAudits, groups); | ||
| element.append(...clumpElems); | ||
| return element; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,7 +68,17 @@ describe('PerfCategoryRenderer', () => { | |
| it('renders the sections', () => { | ||
| const categoryDOM = renderer.render(category, sampleResults.categoryGroups); | ||
| const sections = categoryDOM.querySelectorAll('.lh-category > .lh-audit-group'); | ||
| assert.equal(sections.length, 5); | ||
| const sectionTitles = Array.from(sections).map(el => el.className); | ||
| expect(sectionTitles).toMatchInlineSnapshot(` | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😍 |
||
| Array [ | ||
| "lh-audit-group lh-audit-group--metrics", | ||
| "lh-audit-group lh-audit-group--budgets", | ||
| "lh-audit-group lh-audit-group--load-opportunities", | ||
| "lh-audit-group lh-audit-group--diagnostics", | ||
| "lh-clump lh-audit-group lh-clump--passed", | ||
| "lh-clump lh-audit-group lh-clump--notapplicable", | ||
| ] | ||
| `); | ||
| }); | ||
|
|
||
| it('renders the metrics', () => { | ||
|
|
@@ -150,11 +160,18 @@ describe('PerfCategoryRenderer', () => { | |
| const categoryDOM = renderer.render(category, sampleResults.categoryGroups); | ||
| const passedSection = categoryDOM.querySelector('.lh-category > .lh-clump--passed'); | ||
|
|
||
| const passedAudits = category.auditRefs.filter(audit => | ||
| audit.group && audit.group !== 'metrics' && audit.id !== 'performance-budget' | ||
| && Util.showAsPassed(audit.result)); | ||
| const passedAudits = category.auditRefs.filter( | ||
|
||
| audit => | ||
| audit.group && | ||
| audit.group !== 'metrics' && | ||
| audit.id !== 'performance-budget' && | ||
| Util.showAsPassed(audit.result) && | ||
| audit.result.scoreDisplayMode !== 'notApplicable' | ||
| ).map(ref => ref.id); | ||
|
|
||
| const passedElements = passedSection.querySelectorAll('.lh-audit'); | ||
| assert.equal(passedElements.length, passedAudits.length); | ||
| const passedElemIds = Array.from(passedElements).map(el => el.id); | ||
| expect(passedAudits).toEqual(passedElemIds); | ||
| }); | ||
|
|
||
| // Unsupported by perf cat renderer right now. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.