diff --git a/lighthouse-core/report/html/renderer/util.js b/lighthouse-core/report/html/renderer/util.js index 875a89f6632d..cd2cc4535db8 100644 --- a/lighthouse-core/report/html/renderer/util.js +++ b/lighthouse-core/report/html/renderer/util.js @@ -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 => { diff --git a/lighthouse-core/test/report/html/renderer/report-renderer-test.js b/lighthouse-core/test/report/html/renderer/report-renderer-test.js index 22c3fee12199..37850907f423 100644 --- a/lighthouse-core/test/report/html/renderer/report-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/report-renderer-test.js @@ -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); + }); }); diff --git a/lighthouse-core/test/report/html/renderer/util-test.js b/lighthouse-core/test/report/html/renderer/util-test.js index e870d48fdc68..bb33a218d6f8 100644 --- a/lighthouse-core/test/report/html/renderer/util-test.js +++ b/lighthouse-core/test/report/html/renderer/util-test.js @@ -7,6 +7,7 @@ const assert = require('assert'); const Util = require('../../../../report/html/renderer/util.js'); +const sampleResult = require('../../../results/sample_v2.json'); const NBSP = '\xa0'; @@ -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); + }); + }); });