mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
36 lines
924 B
Plaintext
36 lines
924 B
Plaintext
```ts
|
|
// .storybook/test-runner.ts
|
|
|
|
import type { TestRunnerConfig } from '@storybook/test-runner';
|
|
import { getStoryContext } from '@storybook/test-runner';
|
|
|
|
import { injectAxe, checkA11y } from 'axe-playwright';
|
|
|
|
/*
|
|
* See https://storybook.js.org/docs/writing-tests/test-runner#test-hook-api
|
|
* to learn more about the test-runner hooks API.
|
|
*/
|
|
const config: TestRunnerConfig = {
|
|
async preVisit(page) {
|
|
await injectAxe(page);
|
|
},
|
|
async postVisit(page, context) {
|
|
// Get the entire context of a story, including parameters, args, argTypes, etc.
|
|
const storyContext = await getStoryContext(page, context);
|
|
|
|
// Do not run a11y tests on disabled stories.
|
|
if (storyContext.parameters?.a11y?.disable) {
|
|
return;
|
|
}
|
|
await checkA11y(page, '#storybook-root', {
|
|
detailedReport: true,
|
|
detailedReportOptions: {
|
|
html: true,
|
|
},
|
|
});
|
|
},
|
|
};
|
|
|
|
export default config;
|
|
```
|