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

report(flow): refine snapshot and timespan performance #13184

Merged
merged 12 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flow-report/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
width: max-content;
background-color: var(--report-background-color);
border: 1px solid var(--color-gray-900);
border-radius: 5px;
border-radius: 3px;
padding: var(--base-spacing);
right: 0;
box-shadow: 0px 4px 4px var(--summary-tooltip-box-shadow-color);
Expand Down
14 changes: 13 additions & 1 deletion flow-report/src/summary/category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export const SummaryTooltip: FunctionComponent<{
gatherMode: LH.Result.GatherMode
}> = ({category, gatherMode}) => {
const strings = useUIStrings();
const {numPassed, numAudits, totalWeight} = Util.calculateCategoryFraction(category);
const {
numPassed,
numAudits,
numInformative,
totalWeight,
} = Util.calculateCategoryFraction(category);

const displayAsFraction = Util.shouldDisplayAsFraction(gatherMode);
const rating = displayAsFraction ?
Expand Down Expand Up @@ -66,6 +71,13 @@ export const SummaryTooltip: FunctionComponent<{
<div className="SummaryTooltip__fraction">
{`${numPassed} audits passed / ${numAudits} audits run`}
</div>
{
numInformative ?
<div className="SummaryTooltip__informative">
{`${numInformative} informative audits`}
</div> :
null
}
</div>
);
};
Expand Down
39 changes: 30 additions & 9 deletions flow-report/test/summary/category-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe('SummaryTooltip', () => {
const category: any = {
score: 1,
auditRefs: [
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1},
{result: {score: 0, scoreDisplayMode: 'binary'}, weight: 1},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1, group: 'diagnostics'},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1, group: 'diagnostics'},
{result: {score: 0, scoreDisplayMode: 'binary'}, weight: 1, group: 'diagnostics'},
],
};

Expand All @@ -50,9 +50,9 @@ describe('SummaryTooltip', () => {
const category: any = {
score: 1,
auditRefs: [
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 0},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 0},
{result: {score: 0, scoreDisplayMode: 'binary'}, weight: 0},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 0, group: 'diagnostics'},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 0, group: 'diagnostics'},
{result: {score: 0, scoreDisplayMode: 'binary'}, weight: 0, group: 'diagnostics'},
],
};

Expand All @@ -70,9 +70,9 @@ describe('SummaryTooltip', () => {
const category: any = {
score: 1,
auditRefs: [
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1},
{result: {score: 0, scoreDisplayMode: 'binary'}, weight: 1},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1, group: 'diagnostics'},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1, group: 'diagnostics'},
{result: {score: 0, scoreDisplayMode: 'binary'}, weight: 1, group: 'diagnostics'},
],
};

Expand All @@ -85,4 +85,25 @@ describe('SummaryTooltip', () => {
expect(root.getByText('100')).toBeTruthy();
expect(root.getByText('2 audits passed / 3 audits run')).toBeTruthy();
});

it('renders informative audit count if any', async () => {
const category: any = {
score: 1,
auditRefs: [
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1, group: 'diagnostics'},
{result: {score: 1, scoreDisplayMode: 'binary'}, weight: 1, group: 'diagnostics'},
{result: {score: 0, scoreDisplayMode: 'informative'}, weight: 1, group: 'diagnostics'},
],
};

const root = render(
<SummaryTooltip category={category} gatherMode="navigation"/>,
{wrapper}
);

expect(root.getByText('Good')).toBeTruthy();
expect(root.getByText('100')).toBeTruthy();
expect(root.getByText('2 audits passed / 2 audits run')).toBeTruthy();
expect(root.getByText('1 informative audits')).toBeTruthy();
});
});
42 changes: 22 additions & 20 deletions report/renderer/performance-category-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,33 +172,35 @@ export class PerformanceCategoryRenderer extends CategoryRenderer {
}

// Metrics.
const metricAuditsEl = this.renderAuditGroup(groups.metrics);
const metricAudits = category.auditRefs.filter(audit => audit.group === 'metrics');
if (metricAudits.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

oof, really reveals the length of this function 😬

const metricAuditsEl = this.renderAuditGroup(groups.metrics);

// Metric descriptions toggle.
const toggleTmpl = this.dom.createComponent('metricsToggle');
const _toggleEl = this.dom.find('.lh-metrics-toggle', toggleTmpl);
metricAuditsEl.append(..._toggleEl.childNodes);
// Metric descriptions toggle.
const toggleTmpl = this.dom.createComponent('metricsToggle');
const _toggleEl = this.dom.find('.lh-metrics-toggle', toggleTmpl);
metricAuditsEl.append(..._toggleEl.childNodes);

const metricAudits = category.auditRefs.filter(audit => audit.group === 'metrics');
const metricsBoxesEl = this.dom.createChildOf(metricAuditsEl, 'div', 'lh-metrics-container');
const metricsBoxesEl = this.dom.createChildOf(metricAuditsEl, 'div', 'lh-metrics-container');

metricAudits.forEach(item => {
metricsBoxesEl.appendChild(this._renderMetric(item));
});
metricAudits.forEach(item => {
metricsBoxesEl.appendChild(this._renderMetric(item));
});

const estValuesEl = this.dom.createChildOf(metricAuditsEl, 'div', 'lh-metrics__disclaimer');
const disclaimerEl = this.dom.convertMarkdownLinkSnippets(strings.varianceDisclaimer);
estValuesEl.appendChild(disclaimerEl);
const estValuesEl = this.dom.createChildOf(metricAuditsEl, 'div', 'lh-metrics__disclaimer');
const disclaimerEl = this.dom.convertMarkdownLinkSnippets(strings.varianceDisclaimer);
estValuesEl.appendChild(disclaimerEl);

// Add link to score calculator.
const calculatorLink = this.dom.createChildOf(estValuesEl, 'a', 'lh-calclink');
calculatorLink.target = '_blank';
calculatorLink.textContent = strings.calculatorLink;
this.dom.safelySetHref(calculatorLink, this._getScoringCalculatorHref(category.auditRefs));
// Add link to score calculator.
const calculatorLink = this.dom.createChildOf(estValuesEl, 'a', 'lh-calclink');
calculatorLink.target = '_blank';
calculatorLink.textContent = strings.calculatorLink;
this.dom.safelySetHref(calculatorLink, this._getScoringCalculatorHref(category.auditRefs));


metricAuditsEl.classList.add('lh-audit-group--metrics');
element.appendChild(metricAuditsEl);
metricAuditsEl.classList.add('lh-audit-group--metrics');
element.appendChild(metricAuditsEl);
}

// Filmstrip
const timelineEl = this.dom.createChildOf(element, 'div', 'lh-filmstrip-container');
Expand Down
21 changes: 17 additions & 4 deletions report/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,28 @@ export class Util {
* @param {LH.ReportResult.Category} category
*/
static calculateCategoryFraction(category) {
const numAudits = category.auditRefs.length;

let numAudits = 0;
let numPassed = 0;
let numInformative = 0;
let totalWeight = 0;
for (const auditRef of category.auditRefs) {
const auditPassed = Util.showAsPassed(auditRef.result);

// Don't count the audit if it's manual or isn't displayed.
if (!auditRef.group || auditRef.result.scoreDisplayMode === 'manual') {
Copy link
Member

Choose a reason for hiding this comment

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

FWIW I'm pretty sure we only enforce no group === not displayed in performance-category-renderer. It looks like it's the de facto rule now, but only because every non-manual, non-perf audit appears to have a group assigned in the default config since #10623

Copy link
Member Author

Choose a reason for hiding this comment

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

To be safe I added a category.id === 'performance' condition

continue;
} else if (auditRef.result.scoreDisplayMode === 'informative') {
if (!auditPassed) {
++numInformative;
}
continue;
}

++numAudits;
totalWeight += auditRef.weight;
if (Util.showAsPassed(auditRef.result)) numPassed++;
if (auditPassed) numPassed++;
}
return {numPassed, numAudits, totalWeight};
return {numPassed, numAudits, numInformative, totalWeight};
}
}

Expand Down
12 changes: 12 additions & 0 deletions report/test/renderer/performance-category-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ describe('PerfCategoryRenderer', () => {
assert.equal(timelineElements.length + nontimelineElements.length, metricAudits.length);
});

it('does not render metrics section if no metric group audits', () => {
// Remove metrics from category
const newCategory = JSON.parse(JSON.stringify(category));
newCategory.auditRefs = category.auditRefs.filter(audit => audit.group !== 'metrics');

const categoryDOM = renderer.render(newCategory, sampleResults.categoryGroups);
const sections = categoryDOM.querySelectorAll('.lh-category > .lh-audit-group');
const metricSection = categoryDOM.querySelector('.lh-audit-group--metrics');
assert.ok(!metricSection);
assert.equal(sections.length, 4);
});

it('renders the metrics variance disclaimer as markdown', () => {
const categoryDOM = renderer.render(category, sampleResults.categoryGroups);
const disclaimerEl =
Expand Down
50 changes: 46 additions & 4 deletions report/test/renderer/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,58 @@ describe('util helpers', () => {
it('returns passed audits and total audits', () => {
const category = {
auditRefs: [
{weight: 3, result: {score: 1, scoreDisplayMode: 'binary'}},
{weight: 2, result: {score: 1, scoreDisplayMode: 'binary'}},
{weight: 0, result: {score: 1, scoreDisplayMode: 'binary'}},
{weight: 1, result: {score: 0, scoreDisplayMode: 'binary'}},
{weight: 3, result: {score: 1, scoreDisplayMode: 'binary'}, group: 'diagnostics'},
{weight: 2, result: {score: 1, scoreDisplayMode: 'binary'}, group: 'diagnostics'},
{weight: 0, result: {score: 1, scoreDisplayMode: 'binary'}, group: 'diagnostics'},
{weight: 1, result: {score: 0, scoreDisplayMode: 'binary'}, group: 'diagnostics'},
],
};
const {numPassed, numAudits, totalWeight} = Util.calculateCategoryFraction(category);
expect(numPassed).toEqual(3);
expect(numAudits).toEqual(4);
expect(totalWeight).toEqual(6);
const fraction = Util.calculateCategoryFraction(category);
expect(fraction).toEqual({
numAudits: 4,
numPassed: 3,
numInformative: 0,
totalWeight: 6,
});
});

it('ignores manual audits and audits with no group', () => {
const category = {
auditRefs: [
{weight: 1, result: {score: 1, scoreDisplayMode: 'binary'}, group: 'diagnostics'},
{weight: 1, result: {score: 1, scoreDisplayMode: 'binary'}},
{weight: 1, result: {score: 0, scoreDisplayMode: 'manual'}, group: 'diagnostics'},
],
};
const fraction = Util.calculateCategoryFraction(category);
expect(fraction).toEqual({
numAudits: 1,
numPassed: 1,
numInformative: 0,
totalWeight: 1,
});
});

it('tracks informative audits separately', () => {
const category = {
auditRefs: [
{weight: 1, result: {score: 1, scoreDisplayMode: 'binary'}, group: 'diagnostics'},
{weight: 1, result: {score: 1, scoreDisplayMode: 'binary'}, group: 'diagnostics'},
{weight: 0, result: {score: 1, scoreDisplayMode: 'informative'}, group: 'diagnostics'},
{weight: 1, result: {score: 0, scoreDisplayMode: 'informative'}, group: 'diagnostics'},
],
};
const fraction = Util.calculateCategoryFraction(category);
expect(fraction).toEqual({
numAudits: 2,
numPassed: 2,
numInformative: 2,
totalWeight: 2,
});
});
});
});