forked from adobe/react-spectrum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-runner.js
39 lines (35 loc) · 1.11 KB
/
test-runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const {configureAxe, checkA11y, injectAxe} = require('axe-playwright');
const {getStoryContext} = require('@storybook/test-runner');
/*
* See https://storybook.js.org/docs/react/writing-tests/test-runner#test-hook-api-experimental
* to learn more about the test-runner hooks API.
*/
module.exports = {
async preRender(page) {
await injectAxe(page);
},
async postRender(page, context) {
// Grab accessibility settings from the story itself
const storyContext = await getStoryContext(page, context);
if (storyContext.parameters?.a11y?.disable) {
return;
}
await configureAxe(page, {
// TODO: Ideally would have a selector target for the storybook's sb main body element
rules: [
{
id: 'aria-hidden-focus',
selector: 'body *:not([data-a11y-ignore="aria-hidden-focus"])',
},
...(storyContext.parameters?.a11y?.config?.rules ?? [])
]
});
await checkA11y(page, '#root', {
detailedReport: true,
detailedReportOptions: {
html: true,
},
axeOptions: storyContext.parameters?.a11y?.options,
});
},
};