-
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 all 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 |
|---|---|---|
|
|
@@ -210,23 +210,26 @@ 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 thumbnailResult = thumbnailAudit && thumbnailAudit.result; | ||
| if (thumbnailResult && thumbnailResult.details) { | ||
| timelineEl.id = thumbnailResult.id; | ||
| const filmstripEl = this.detailsRenderer.render(thumbnailResult.details); | ||
| filmstripEl && timelineEl.appendChild(filmstripEl); | ||
| // We only expect one of these, but the renderer will support multiple | ||
| const thumbnailAudits = category.auditRefs.filter(audit => audit.group === 'filmstrip'); | ||
|
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. Is this breaking? v7? or: support as fallback the old way.
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. yeah this would break formatting the v6 reports in a new renderer. good call. i'll add a compat bit to also the |
||
| for (const thumbnailAudit of thumbnailAudits) { | ||
| const result = thumbnailAudit.result; | ||
| if (result && result.details) { | ||
| timelineEl.id = result.id; | ||
| const filmstripEl = this.detailsRenderer.render(result.details); | ||
| filmstripEl && timelineEl.appendChild(filmstripEl); | ||
| } | ||
| } | ||
|
|
||
| // Budgets | ||
| /** @type {Array<Element>} */ | ||
| const budgetTableEls = []; | ||
| ['performance-budget', 'timing-budget'].forEach((id) => { | ||
| const audit = category.auditRefs.find(audit => audit.id === id); | ||
| const budgetAudits = category.auditRefs.filter(audit => audit.group === 'budgets'); | ||
| budgetAudits.forEach(audit => { | ||
| if (audit && audit.result.details) { | ||
| const table = this.detailsRenderer.render(audit.result.details); | ||
| if (table) { | ||
| table.id = id; | ||
| table.id = audit.id; | ||
| table.classList.add('lh-audit'); | ||
| budgetTableEls.push(table); | ||
| } | ||
|
|
@@ -281,19 +284,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)); | ||
|
|
||
| if (!passedAudits.length) return element; | ||
| // Everything else (passed, passed with warnings, n/a) | ||
| const renderedAudits = [...metricAudits, ...thumbnailAudits, ...budgetAudits, | ||
| ...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. |
||
|
|
||
| const clumpOpts = { | ||
| auditRefs: passedAudits, | ||
| groupDefinitions: groups, | ||
| }; | ||
| const passedElem = this.renderClump('passed', clumpOpts); | ||
| element.appendChild(passedElem); | ||
| const clumpElems = this.renderClumps(remainingAudits, groups); | ||
| element.append(...clumpElems); | ||
| return element; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,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', () => { | ||
|
|
@@ -166,11 +176,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 passedAuditIds = 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(passedAuditIds).toEqual(passedElemIds); | ||
| }); | ||
|
|
||
| // Unsupported by perf cat renderer right 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.
(the diff is a little funny here because i moved the diagram... but the method signature and top 3 lines are identical to what it had been.)
git diff catches the changes as a "move", and calls out the new method of renderClumps a bit more clearer