Skip to content

Commit

Permalink
configure storybook for a11y testing
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleSeo committed Dec 13, 2024
1 parent eafebef commit aa3b1f2
Show file tree
Hide file tree
Showing 5 changed files with 13,132 additions and 15 deletions.
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const config: StorybookConfig = {
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
"@storybook/addon-a11y"
],
framework: {
name: "@storybook/react-vite",
Expand Down
33 changes: 33 additions & 0 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { TestRunnerConfig } from "@storybook/test-runner";
import { getStoryContext } from "@storybook/test-runner";

import { injectAxe, checkA11y, configureAxe } 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);

// Apply story-level a11y rules
await configureAxe(page, {
rules: storyContext.parameters?.a11y?.config?.rules,
});

const element = storyContext.parameters?.a11y?.element ?? "#storybook-root";
await checkA11y(page, element, {
detailedReport: true,
detailedReportOptions: {
html: true,
},
});
},
};

export default config;
Binary file modified bun.lockb
Binary file not shown.
Loading

0 comments on commit aa3b1f2

Please sign in to comment.