1 | import AxePuppeteer from '@axe-core/puppeteer';
|
2 | import { defaultAxeConfig } from './config';
|
3 | import { puppeteerTest } from './puppeteerTest';
|
4 | export const axeTest = (customConfig = {}) => {
|
5 | const extendedConfig = { ...defaultAxeConfig, ...customConfig };
|
6 | const { beforeAxeTest } = extendedConfig;
|
7 | return puppeteerTest({
|
8 | ...extendedConfig,
|
9 | async testBody(page, testOptions) {
|
10 | const { element = '#storybook-root', exclude, disabledRules, options, config, } = testOptions.context.parameters.a11y || {};
|
11 | await beforeAxeTest(page, options);
|
12 | const axe = new AxePuppeteer(page);
|
13 | axe.include(element);
|
14 | if (exclude) {
|
15 | axe.exclude(exclude);
|
16 | }
|
17 | if (options) {
|
18 | axe.options(options);
|
19 | }
|
20 | if (disabledRules) {
|
21 | axe.disableRules(disabledRules);
|
22 | }
|
23 | if (config) {
|
24 | axe.configure(config);
|
25 | }
|
26 | const { violations } = await axe.analyze();
|
27 | expect(violations).toHaveLength(0);
|
28 | },
|
29 | });
|
30 | };
|