Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storybook a11y tests with Storybook Test Runner #383

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/react-components/.storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// .storybook/test-runner.ts
// From: https://storybook.js.org/docs/writing-tests/accessibility-testing#setup

import type { TestRunnerConfig } 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) {
await checkA11y(page, "#storybook-root");
},
};

export default config;
8 changes: 8 additions & 0 deletions packages/react-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,20 @@ This project follows semantic versioning. See [CHANGELOG.md](./CHANGELOG.md) for

Components live in `./src/components` and are targeted by the build process with an export in `./src/index.ts`.

#### Testing components with Jest

Unit tests can be run with Jest using `npm run test`.

### Storybook

Storybook stories live in `./src/stories`.

Run `npm run storybook-dev` to access the Storybook instance for the component library.

#### Testing with Storybook Test Runner

With Storybook running locally, use the `npm run test-storybook` script to run `@storybook/test-runner` using the configuration defined in `./.storybook/test-runner.ts`. [Learn more about Storybook Test Runner](https://storybook.js.org/docs/writing-tests/test-runner).

### Vite kitchen sink application

Vite uses the components code directly from `./src/components` in groups of content in `./src/pages`.
Expand Down
Loading