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(test): split out axe test #13142

Merged
merged 1 commit into from
Sep 29, 2021
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
86 changes: 86 additions & 0 deletions report/test/renderer/report-renderer-axe-test.js
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
);
});
});
55 changes: 0 additions & 55 deletions report/test/renderer/report-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,59 +233,4 @@ describe('ReportRenderer', () => {
.querySelectorAll('.lh-audit--notapplicable').length;
assert.strictEqual(notApplicableCount, notApplicableElementCount);
});

describe('axe-core', () => {
let axe;

beforeAll(async () =>{
// Needed by axe-core
// https://github.com/dequelabs/axe-core/blob/581c441c/doc/examples/jsdom/test/a11y.js#L24
global.window = global.self;
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);
});
});