From 41977eb627ccddb74de68eddc31981603847b8c2 Mon Sep 17 00:00:00 2001 From: Shane Exterkamp Date: Wed, 12 Dec 2018 13:26:35 -0800 Subject: [PATCH 1/9] Replaced not-applicable with notApplicable. --- .../offline-local/offline-expectations.js | 26 ++++----- .../test/smokehouse/seo/expectations.js | 2 +- lighthouse-core/audits/audit.js | 2 +- lighthouse-core/lib/proto-preprocessor.js | 5 +- .../report/html/renderer/category-renderer.js | 8 +-- lighthouse-core/report/html/renderer/util.js | 5 +- lighthouse-core/test/audits/audit-test.js | 2 +- .../test/lib/proto-preprocessor-test.js | 2 +- .../html/renderer/category-renderer-test.js | 6 +- .../html/renderer/report-renderer-test.js | 5 +- .../test/report/html/renderer/util-test.js | 4 +- lighthouse-core/test/results/sample_v2.json | 56 +++++++++---------- lighthouse-core/test/scoring-test.js | 4 +- proto/lighthouse-result.proto | 1 + proto/sample_v2_round_trip.json | 56 +++++++++---------- types/audit.d.ts | 4 +- types/lhr-lite.d.ts | 4 +- 17 files changed, 98 insertions(+), 94 deletions(-) diff --git a/lighthouse-cli/test/smokehouse/offline-local/offline-expectations.js b/lighthouse-cli/test/smokehouse/offline-local/offline-expectations.js index f139b0185fd0..4f7d46ca44f6 100644 --- a/lighthouse-cli/test/smokehouse/offline-local/offline-expectations.js +++ b/lighthouse-cli/test/smokehouse/offline-local/offline-expectations.js @@ -58,10 +58,10 @@ module.exports = [ score: 1, }, 'user-timings': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'critical-request-chains': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'installable-manifest': { score: 0, @@ -75,22 +75,22 @@ module.exports = [ score: 0, }, 'aria-valid-attr': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'aria-allowed-attr': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'color-contrast': { score: 1, }, 'image-alt': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'label': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'tabindex': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'content-width': { score: 1, @@ -121,10 +121,10 @@ module.exports = [ score: 1, }, 'user-timings': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'critical-request-chains': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'installable-manifest': { score: 1, @@ -136,10 +136,10 @@ module.exports = [ score: 0, }, 'aria-valid-attr': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'aria-allowed-attr': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'color-contrast': { score: 1, @@ -148,10 +148,10 @@ module.exports = [ score: 0, }, 'label': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'tabindex': { - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, 'content-width': { score: 1, diff --git a/lighthouse-cli/test/smokehouse/seo/expectations.js b/lighthouse-cli/test/smokehouse/seo/expectations.js index 7e36d3655433..224013436148 100644 --- a/lighthouse-cli/test/smokehouse/seo/expectations.js +++ b/lighthouse-cli/test/smokehouse/seo/expectations.js @@ -73,7 +73,7 @@ module.exports = [ }, 'robots-txt': { rawValue: true, - scoreDisplayMode: 'not-applicable', + scoreDisplayMode: 'notApplicable', }, }, }, diff --git a/lighthouse-core/audits/audit.js b/lighthouse-core/audits/audit.js index dfaf6668a614..9eff46f948f9 100644 --- a/lighthouse-core/audits/audit.js +++ b/lighthouse-core/audits/audit.js @@ -34,7 +34,7 @@ class Audit { BINARY: 'binary', MANUAL: 'manual', INFORMATIVE: 'informative', - NOT_APPLICABLE: 'not-applicable', + NOT_APPLICABLE: 'notApplicable', ERROR: 'error', }; } diff --git a/lighthouse-core/lib/proto-preprocessor.js b/lighthouse-core/lib/proto-preprocessor.js index 454037f73c9b..8b9524faba18 100644 --- a/lighthouse-core/lib/proto-preprocessor.js +++ b/lighthouse-core/lib/proto-preprocessor.js @@ -45,9 +45,12 @@ function processForProto(result) { // Rewrite the 'not-applicable' scoreDisplayMode to 'not_applicable'. #6201 if (audit.scoreDisplayMode) { + // @ts-ignore ts properly flags this as invalid as it should not happen, + // but remains in preprocessor to protect from proto translation errors from + // old LHRs. if (audit.scoreDisplayMode === 'not-applicable') { // @ts-ignore Breaking the LH.Result type - audit.scoreDisplayMode = 'not_applicable'; + audit.scoreDisplayMode = 'notApplicable'; } } // Drop raw values. #6199 diff --git a/lighthouse-core/report/html/renderer/category-renderer.js b/lighthouse-core/report/html/renderer/category-renderer.js index f455b9b2de46..e39a80402d04 100644 --- a/lighthouse-core/report/html/renderer/category-renderer.js +++ b/lighthouse-core/report/html/renderer/category-renderer.js @@ -22,7 +22,7 @@ /** @typedef {import('./report-renderer.js')} ReportRenderer */ /** @typedef {import('./details-renderer.js')} DetailsRenderer */ /** @typedef {import('./util.js')} Util */ -/** @typedef {'failed'|'manual'|'passed'|'not-applicable'} TopLevelClumpId */ +/** @typedef {'failed'|'manual'|'passed'|'notApplicable'} TopLevelClumpId */ class CategoryRenderer { /** @@ -56,7 +56,7 @@ class CategoryRenderer { title: Util.UIStrings.passedAuditsGroupTitle, className: 'lh-clump--passed', }, - 'not-applicable': { + 'notApplicable': { title: Util.UIStrings.notApplicableAuditsGroupTitle, className: 'lh-clump--not-applicable', }, @@ -370,7 +370,7 @@ class CategoryRenderer { */ _getClumpIdForAuditRef(auditRef) { const scoreDisplayMode = auditRef.result.scoreDisplayMode; - if (scoreDisplayMode === 'manual' || scoreDisplayMode === 'not-applicable') { + if (scoreDisplayMode === 'manual' || scoreDisplayMode === 'notApplicable') { return scoreDisplayMode; } @@ -397,7 +397,7 @@ class CategoryRenderer { clumps.set('failed', []); clumps.set('manual', []); clumps.set('passed', []); - clumps.set('not-applicable', []); + clumps.set('notApplicable', []); // Sort audits into clumps. for (const auditRef of category.auditRefs) { diff --git a/lighthouse-core/report/html/renderer/util.js b/lighthouse-core/report/html/renderer/util.js index cd2cc4535db8..c2f134a3adbd 100644 --- a/lighthouse-core/report/html/renderer/util.js +++ b/lighthouse-core/report/html/renderer/util.js @@ -66,8 +66,9 @@ class Util { // 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. + // TODO(exterkamp): remove this when proto enum removes 'not_applicable' if (audit.scoreDisplayMode === 'not_applicable') { - audit.scoreDisplayMode = 'not-applicable'; + audit.scoreDisplayMode = 'notApplicable'; } } @@ -163,7 +164,7 @@ class Util { */ static calculateRating(score, scoreDisplayMode) { // Handle edge cases first, manual and not applicable receive 'pass', errored audits receive 'error' - if (scoreDisplayMode === 'manual' || scoreDisplayMode === 'not-applicable') { + if (scoreDisplayMode === 'manual' || scoreDisplayMode === 'notApplicable') { return RATINGS.PASS.label; } else if (scoreDisplayMode === 'error') { return RATINGS.ERROR.label; diff --git a/lighthouse-core/test/audits/audit-test.js b/lighthouse-core/test/audits/audit-test.js index 804f9441f8dd..0e4251a2ca0d 100644 --- a/lighthouse-core/test/audits/audit-test.js +++ b/lighthouse-core/test/audits/audit-test.js @@ -90,7 +90,7 @@ describe('Audit', () => { const providedResult = {rawValue: true, notApplicable: true}; const result = Audit.generateAuditResult(B, providedResult); assert.equal(result.score, null); - assert.equal(result.scoreDisplayMode, 'not-applicable'); + assert.equal(result.scoreDisplayMode, 'notApplicable'); }); it('sets state of failed audits', () => { diff --git a/lighthouse-core/test/lib/proto-preprocessor-test.js b/lighthouse-core/test/lib/proto-preprocessor-test.js index 3a76964d68e5..8dcb2283b946 100644 --- a/lighthouse-core/test/lib/proto-preprocessor-test.js +++ b/lighthouse-core/test/lib/proto-preprocessor-test.js @@ -87,7 +87,7 @@ describe('processing for proto', () => { const expectation = { 'audits': { 'critical-request-chains': { - 'scoreDisplayMode': 'not_applicable', + 'scoreDisplayMode': 'notApplicable', 'displayValue': 'hello %d | 123', }, }, diff --git a/lighthouse-core/test/report/html/renderer/category-renderer-test.js b/lighthouse-core/test/report/html/renderer/category-renderer-test.js index ad69de5b04f7..ee474c40a3e4 100644 --- a/lighthouse-core/test/report/html/renderer/category-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/category-renderer-test.js @@ -161,7 +161,7 @@ describe('CategoryRenderer', () => { '.lh-clump--not-applicable .lh-audit-group__summary')); const notApplicableCount = a11yCategory.auditRefs.reduce((sum, audit) => - sum += audit.result.scoreDisplayMode === 'not-applicable' ? 1 : 0, 0); + sum += audit.result.scoreDisplayMode === 'notApplicable' ? 1 : 0, 0); assert.equal( categoryDOM.querySelectorAll('.lh-clump--not-applicable .lh-audit').length, notApplicableCount, @@ -202,7 +202,7 @@ describe('CategoryRenderer', () => { it.skip('renders the failed audits grouped by group', () => { const categoryDOM = renderer.render(category, sampleResults.categoryGroups); const failedAudits = category.auditRefs.filter(audit => { - return audit.result.score !== 1 && !audit.result.scoreDisplayMode === 'not-applicable'; + return audit.result.score !== 1 && !audit.result.scoreDisplayMode === 'notApplicable'; }); const failedAuditTags = new Set(failedAudits.map(audit => audit.group)); @@ -213,7 +213,7 @@ describe('CategoryRenderer', () => { it('renders the passed audits grouped by group', () => { const categoryDOM = renderer.render(category, sampleResults.categoryGroups); const passedAudits = category.auditRefs.filter(audit => - audit.result.scoreDisplayMode !== 'not-applicable' && audit.result.score === 1); + audit.result.scoreDisplayMode !== 'notApplicable' && audit.result.score === 1); const passedAuditTags = new Set(passedAudits.map(audit => audit.group)); const passedAuditGroups = categoryDOM.querySelectorAll('.lh-clump--passed .lh-audit-group'); 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 db6269cb6d5b..739ec74b62c8 100644 --- a/lighthouse-core/test/report/html/renderer/report-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/report-renderer-test.js @@ -185,7 +185,7 @@ describe('ReportRenderer', () => { let notApplicableCount = 0; Object.values(clonedSampleResult.audits).forEach(audit => { - if (audit.scoreDisplayMode === 'not-applicable') { + if (audit.scoreDisplayMode === 'notApplicable') { notApplicableCount++; audit.scoreDisplayMode = 'not_applicable'; } @@ -196,8 +196,7 @@ describe('ReportRenderer', () => { const container = renderer._dom._document.body; const reportElement = renderer.renderReport(sampleResults, container); const notApplicableElementCount = reportElement - .querySelectorAll('.lh-audit--not-applicable').length; - + .querySelectorAll('.lh-audit--notApplicable').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 bb33a218d6f8..6fcd9b5a3120 100644 --- a/lighthouse-core/test/report/html/renderer/util-test.js +++ b/lighthouse-core/test/report/html/renderer/util-test.js @@ -171,12 +171,12 @@ describe('util helpers', () => { }); describe('#prepareReportResult', () => { - it('corrects underscored `not-applicable` scoreDisplayMode', () => { + it('corrects underscored `notApplicable` scoreDisplayMode', () => { const clonedSampleResult = JSON.parse(JSON.stringify(sampleResult)); let notApplicableCount = 0; Object.values(clonedSampleResult.audits).forEach(audit => { - if (audit.scoreDisplayMode === 'not-applicable') { + if (audit.scoreDisplayMode === 'notApplicable') { notApplicableCount++; audit.scoreDisplayMode = 'not_applicable'; } diff --git a/lighthouse-core/test/results/sample_v2.json b/lighthouse-core/test/results/sample_v2.json index cb09a0e23451..d4aeb2dff6bb 100644 --- a/lighthouse-core/test/results/sample_v2.json +++ b/lighthouse-core/test/results/sample_v2.json @@ -290,7 +290,7 @@ "title": "User Timing marks and measures", "description": "Consider instrumenting your app with the User Timing API to measure your app's real-world performance during key user experiences. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/user-timing).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true, "details": { "type": "table", @@ -1085,7 +1085,7 @@ "title": "`[accesskey]` values are unique", "description": "Access keys let users quickly focus a part of the page. For proper navigation, each access key must be unique. [Learn more](https://dequeuniversity.com/rules/axe/2.2/accesskeys?application=lighthouse).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true }, "aria-allowed-attr": { @@ -1093,7 +1093,7 @@ "title": "`[aria-*]` attributes match their roles", "description": "Each ARIA `role` supports a specific subset of `aria-*` attributes. Mismatching these invalidates the `aria-*` attributes. [Learn more](https://dequeuniversity.com/rules/axe/2.2/aria-allowed-attr?application=lighthouse).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true }, "aria-required-attr": { @@ -1101,7 +1101,7 @@ "title": "`[role]`s have all required `[aria-*]` attributes", "description": "Some ARIA roles have required attributes that describe the state of the element to screen readers. [Learn more](https://dequeuniversity.com/rules/axe/2.2/aria-required-attr?application=lighthouse).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true }, "aria-required-children": { @@ -1109,7 +1109,7 @@ "title": "Elements with `[role]` that require specific children `[role]`s, are present", "description": "Some ARIA parent roles must contain specific child roles to perform their intended accessibility functions. [Learn more](https://dequeuniversity.com/rules/axe/2.2/aria-required-children?application=lighthouse).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true }, "aria-required-parent": { @@ -1117,7 +1117,7 @@ "title": "`[role]`s are contained by their required parent element", "description": "Some ARIA child roles must be contained by specific parent roles to properly perform their intended accessibility functions. [Learn more](https://dequeuniversity.com/rules/axe/2.2/aria-required-parent?application=lighthouse).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true }, "aria-roles": { @@ -1125,7 +1125,7 @@ "title": "`[role]` values are valid", "description": "ARIA roles must have valid values in order to perform their intended accessibility functions. [Learn more](https://dequeuniversity.com/rules/axe/2.2/aria-roles?application=lighthouse).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true }, "aria-valid-attr-value": { @@ -1133,7 +1133,7 @@ "title": "`[aria-*]` attributes have valid values", "description": "Assistive technologies, like screen readers, can't interpret ARIA attributes with invalid values. [Learn more](https://dequeuniversity.com/rules/axe/2.2/aria-valid-attr-value?application=lighthouse).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true }, "aria-valid-attr": { @@ -1141,7 +1141,7 @@ "title": "`[aria-*]` attributes are valid and not misspelled", "description": "Assistive technologies, like screen readers, can't interpret ARIA attributes with invalid names. [Learn more](https://dequeuniversity.com/rules/axe/2.2/aria-valid-attr?application=lighthouse).", "score": null, - "scoreDisplayMode": "not-applicable", + "scoreDisplayMode": "notApplicable", "rawValue": true }, "audio-caption": { @@ -1149,7 +1149,7 @@ "title": "`