-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
report(test): split out axe test (#13142)
- Loading branch information
Showing
2 changed files
with
86 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* @license Copyright 2021 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'; | ||
|
||
/* eslint-env jest */ | ||
|
||
import jsdom from 'jsdom'; | ||
|
||
import {Util} from '../../renderer/util.js'; | ||
import {DOM} from '../../renderer/dom.js'; | ||
import {DetailsRenderer} from '../../renderer/details-renderer.js'; | ||
import {CategoryRenderer} from '../../renderer/category-renderer.js'; | ||
import {ReportRenderer} from '../../renderer/report-renderer.js'; | ||
import sampleResultsOrig from '../../../lighthouse-core/test/results/sample_v2.json'; | ||
|
||
describe('ReportRendererAxe', () => { | ||
describe('with aXe', () => { | ||
let axe; | ||
let renderer; | ||
let sampleResults; | ||
|
||
beforeAll(async () => { | ||
const {window} = new jsdom.JSDOM(); | ||
const dom = new DOM(window.document); | ||
const detailsRenderer = new DetailsRenderer(dom); | ||
const categoryRenderer = new CategoryRenderer(dom, detailsRenderer); | ||
renderer = new ReportRenderer(dom, categoryRenderer); | ||
sampleResults = Util.prepareReportResult(sampleResultsOrig); | ||
|
||
// Needed by axe-core | ||
// https://github.com/dequelabs/axe-core/blob/581c441c/doc/examples/jsdom/test/a11y.js#L24 | ||
global.window = global.self = window; | ||
global.Node = global.self.Node; | ||
global.Element = global.self.Element; | ||
|
||
// axe-core must be imported after the global polyfills | ||
axe = (await import('axe-core')).default; | ||
}); | ||
|
||
afterAll(() => { | ||
global.window = undefined; | ||
global.Node = undefined; | ||
global.Element = undefined; | ||
}); | ||
|
||
it('renders without axe violations', () => { | ||
const container = renderer._dom._document.createElement('main'); | ||
const output = renderer.renderReport(sampleResults, container); | ||
|
||
renderer._dom._document.body.appendChild(container); | ||
|
||
const config = { | ||
rules: { | ||
// Reports may have duplicate ids | ||
// https://github.com/GoogleChrome/lighthouse/issues/9432 | ||
'duplicate-id': {enabled: false}, | ||
'duplicate-id-aria': {enabled: false}, | ||
'landmark-no-duplicate-contentinfo': {enabled: false}, | ||
// The following rules are disable for axe-core + jsdom compatibility | ||
// https://github.com/dequelabs/axe-core/tree/b573b1c1/doc/examples/jest_react#to-run-the-example | ||
'color-contrast': {enabled: false}, | ||
'link-in-text-block': {enabled: false}, | ||
// Report has empty links prior to i18n-ing. | ||
'link-name': {enabled: false}, | ||
// May not be a real issue. https://github.com/dequelabs/axe-core/issues/2958 | ||
'nested-interactive': {enabled: false}, | ||
}, | ||
}; | ||
|
||
return new Promise(resolve => { | ||
axe.run(output, config, (error, {violations}) => { | ||
expect(error).toBeNull(); | ||
expect(violations).toEqual([]); | ||
resolve(); | ||
}); | ||
}); | ||
// This test takes 40s on fast hardware, and 50-60s on GHA. | ||
// https://github.com/dequelabs/axe-core/tree/b573b1c1/doc/examples/jest_react#timeout-issues | ||
}, | ||
/* timeout= */ 100 * 1000 | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters