@storybook/addon-storyshots-puppeteer
Version:
Image snapshots addition to StoryShots based on puppeteer
31 lines (30 loc) • 1.13 kB
JavaScript
import AxePuppeteer from '@axe-core/puppeteer';
import { defaultAxeConfig } from './config';
import { puppeteerTest } from './puppeteerTest';
export const axeTest = (customConfig = {}) => {
const extendedConfig = { ...defaultAxeConfig, ...customConfig };
const { beforeAxeTest } = extendedConfig;
return puppeteerTest({
...extendedConfig,
async testBody(page, testOptions) {
const { element = '#storybook-root', exclude, disabledRules, options, config, } = testOptions.context.parameters.a11y || {};
await beforeAxeTest(page, options);
const axe = new AxePuppeteer(page);
axe.include(element);
if (exclude) {
axe.exclude(exclude);
}
if (options) {
axe.options(options);
}
if (disabledRules) {
axe.disableRules(disabledRules);
}
if (config) {
axe.configure(config);
}
const { violations } = await axe.analyze();
expect(violations).toHaveLength(0);
},
});
};