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: handle underscored not_applicable scoreDisplayMode #6549

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions lighthouse-core/report/html/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ class Util {
if (typeof clone.categories !== 'object') throw new Error('No categories provided.');
clone.reportCategories = Object.values(clone.categories);

// The proto process turns 'not-applicable' into 'not_applicable'. Correct this to support both.
// TODO: remove when underscore/hyphen proto issue is resolved. See #6371, #6201.
for (const audit of Object.values(clone.audits)) {
// @ts-ignore tsc rightly flags that this value shouldn't occur.
if (audit.scoreDisplayMode === 'not_applicable') {
audit.scoreDisplayMode = 'not-applicable';
}
}

// For convenience, smoosh all AuditResults into their auditDfn (which has just weight & group)
for (const category of clone.reportCategories) {
category.auditRefs.forEach(auditMeta => {
Expand Down
21 changes: 21 additions & 0 deletions lighthouse-core/test/report/html/renderer/report-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,25 @@ describe('ReportRenderer', () => {
renderer.setTemplateContext(otherDocument);
assert.equal(renderer._templateContext, otherDocument);
});

it('renders `not_applicable` audits as `not-applicable`', () => {
const clonedSampleResult = JSON.parse(JSON.stringify(sampleResultsOrig));

let notApplicableCount = 0;
Object.values(clonedSampleResult.audits).forEach(audit => {
if (audit.scoreDisplayMode === 'not-applicable') {
notApplicableCount++;
audit.scoreDisplayMode = 'not_applicable';
}
});

assert.ok(notApplicableCount > 20); // Make sure something's being tested.

const container = renderer._dom._document.body;
const reportElement = renderer.renderReport(sampleResults, container);
const notApplicableElementCount = reportElement
.querySelectorAll('.lh-audit--not-applicable').length;

assert.strictEqual(notApplicableCount, notApplicableElementCount);
});
});
21 changes: 21 additions & 0 deletions lighthouse-core/test/report/html/renderer/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const assert = require('assert');
const Util = require('../../../../report/html/renderer/util.js');
const sampleResult = require('../../../results/sample_v2.json');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should add a test of trying to render sample_v2_round_trip.json or better yet, get the no-loss-round-trip test going :)

Copy link
Member Author

Choose a reason for hiding this comment

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

We should definitely do this. And maybe add another puppeteer test to make sure the report looks good. We would have caught this :)


const NBSP = '\xa0';

Expand Down Expand Up @@ -168,4 +169,24 @@ describe('util helpers', () => {
Util.formatDisplayValue(displayValue);
assert.deepStrictEqual(displayValue, cloned, 'displayValue was mutated');
});

describe('#prepareReportResult', () => {
it('corrects underscored `not-applicable` scoreDisplayMode', () => {
const clonedSampleResult = JSON.parse(JSON.stringify(sampleResult));

let notApplicableCount = 0;
Object.values(clonedSampleResult.audits).forEach(audit => {
if (audit.scoreDisplayMode === 'not-applicable') {
notApplicableCount++;
audit.scoreDisplayMode = 'not_applicable';
}
});

assert.ok(notApplicableCount > 20); // Make sure something's being tested.

// Original audit results should be restored.
const preparedResult = Util.prepareReportResult(clonedSampleResult);
assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
});
});
});