From fbc3a9d5b30ab66983c5af41bdd597ea2cecff01 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 16 Sep 2020 19:14:28 -0500 Subject: [PATCH 01/24] href change axe import --- lighthouse-core/audits/seo/hreflang.js | 21 ++++++++------------- lighthouse-core/lib/axe.js | 13 +++++++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 lighthouse-core/lib/axe.js diff --git a/lighthouse-core/audits/seo/hreflang.js b/lighthouse-core/audits/seo/hreflang.js index 061af43db0cd..09277521966f 100644 --- a/lighthouse-core/audits/seo/hreflang.js +++ b/lighthouse-core/audits/seo/hreflang.js @@ -10,9 +10,11 @@ /** @typedef {{reason: string}} SubItem */ const Audit = require('../audit.js'); +const i18n = require('../../lib/i18n/i18n.js'); +const axeLibSource = require('../../lib/axe.js').source; + const VALID_LANGS = importValidLangs(); const NO_LANGUAGE = 'x-default'; -const i18n = require('../../lib/i18n/i18n.js'); const UIStrings = { /** Title of a Lighthouse audit that provides detail on the `hreflang` attribute on a page. This descriptive title is shown when the page's `hreflang` attribute is configured correctly. "hreflang" is an HTML attribute and should not be translated. */ @@ -32,24 +34,17 @@ const UIStrings = { const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings); /** - * Import list of valid languages from axe core without including whole axe-core package + * Import list of valid languages from axe core. * This is a huge array of language codes that can be stored more efficiently if we will need to * shrink the bundle size. * @return {Array} */ function importValidLangs() { - // @ts-expect-error - global switcheroo to load axe valid-langs - const axeCache = global.axe; - // @ts-expect-error - global.axe = {utils: {}}; + // Define a window-ish object so axe will export to it. + const window = {getComputedStyle: () => {}}; + eval(axeLibSource); // @ts-expect-error - require('axe-core/lib/core/utils/valid-langs.js'); - // @ts-expect-error - const validLangs = global.axe.utils.validLangs(); - // @ts-expect-error - global.axe = axeCache; - - return validLangs; + return window.axe.utils.validLangs(); } /** diff --git a/lighthouse-core/lib/axe.js b/lighthouse-core/lib/axe.js new file mode 100644 index 000000000000..aae144e037fd --- /dev/null +++ b/lighthouse-core/lib/axe.js @@ -0,0 +1,13 @@ +/** + * @license Copyright 2020 The Lighthouse Authors. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +const fs = require('fs'); +const source = fs.readFileSync(require.resolve('axe-core/axe.min.js'), 'utf8'); + +module.exports = { + source, +}; From 0d602ddb32063ecd4967ef32b907e8a726720457 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 16 Sep 2020 19:20:59 -0500 Subject: [PATCH 02/24] fix --- lighthouse-core/gather/gatherers/accessibility.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lighthouse-core/gather/gatherers/accessibility.js b/lighthouse-core/gather/gatherers/accessibility.js index 95bdd441de99..d3529f43c614 100644 --- a/lighthouse-core/gather/gatherers/accessibility.js +++ b/lighthouse-core/gather/gatherers/accessibility.js @@ -8,8 +8,7 @@ /* global window, document, getNodeDetails */ const Gatherer = require('./gatherer.js'); -const fs = require('fs'); -const axeLibSource = fs.readFileSync(require.resolve('axe-core/axe.min.js'), 'utf8'); +const axeLibSource = require('../../lib/axe.js').source; const pageFunctions = require('../../lib/page-functions.js'); /** From 9569ff479f4664f86cc46b7e85389e3b768b78d2 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Thu, 12 Nov 2020 16:32:51 -0600 Subject: [PATCH 03/24] wip --- .../audits/accessibility/layout-table.js | 49 ----------- .../audits/accessibility/video-description.js | 46 ---------- lighthouse-core/config/default-config.js | 4 - .../gather/gatherers/accessibility.js | 83 ++++++++++--------- package.json | 2 +- yarn.lock | 8 +- 6 files changed, 50 insertions(+), 142 deletions(-) delete mode 100644 lighthouse-core/audits/accessibility/layout-table.js delete mode 100644 lighthouse-core/audits/accessibility/video-description.js diff --git a/lighthouse-core/audits/accessibility/layout-table.js b/lighthouse-core/audits/accessibility/layout-table.js deleted file mode 100644 index 5982321f240d..000000000000 --- a/lighthouse-core/audits/accessibility/layout-table.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @license Copyright 2017 The Lighthouse Authors. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -/** - * @fileoverview Ensures presentational `` elements do not use `
`, `
` elements - * or the summary attribute. - * See base class in axe-audit.js for audit() implementation. - */ - -const AxeAudit = require('./axe-audit.js'); -const i18n = require('../../lib/i18n/i18n.js'); - -const UIStrings = { - /** Title of an accesibility audit that evaluates if a table intended for layout contains data annotations as it can be confusing for screen readers. This is evaluated by checking if tables with the ARIA role of `presentation` or `none` contain any data elements such as table headers (`
`). This title is descriptive of the successful state and is shown to users when no user action is required. */ - title: 'Presentational `` elements avoid using `
`, `
` or the ' + - '`[summary]` attribute.', - /** Title of an accesibility audit that evaluates if a table intended for layout contains data annotations as it can be confusing for screen readers. This is evaluated by checking if tables with the ARIA role of `presentation` or `none` contain any data elements such as table headers (`
`). This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */ - failureTitle: 'Presentational `` elements do not avoid using `
`, ' + - '`
` or the `[summary]` attribute.', - /** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */ - description: 'A table being used for layout purposes should not include data elements, ' + - 'such as the th or caption elements or the summary attribute, because this can ' + - 'create a confusing experience for screen reader users. ' + - '[Learn more](https://web.dev/layout-table/).', -}; - -const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings); - -class LayoutTable extends AxeAudit { - /** - * @return {LH.Audit.Meta} - */ - static get meta() { - return { - id: 'layout-table', - title: str_(UIStrings.title), - failureTitle: str_(UIStrings.failureTitle), - description: str_(UIStrings.description), - requiredArtifacts: ['Accessibility'], - }; - } -} - -module.exports = LayoutTable; -module.exports.UIStrings = UIStrings; diff --git a/lighthouse-core/audits/accessibility/video-description.js b/lighthouse-core/audits/accessibility/video-description.js deleted file mode 100644 index efce042777af..000000000000 --- a/lighthouse-core/audits/accessibility/video-description.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * @license Copyright 2017 The Lighthouse Authors. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -/** - * @fileoverview Ensures `