Skip to content

Commit

Permalink
test: run axe-playwright a11y tests using test-storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
unekinn committed Sep 11, 2024
1 parent 6ae7cc4 commit 79bdc51
Show file tree
Hide file tree
Showing 4 changed files with 2,547 additions and 102 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- 'biome.jsonc'
jobs:
checks:
name: Lint
name: Lint and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -17,4 +17,14 @@ jobs:
run: yarn biome ci .
- name: Lint CSS
run: yarn lint-style

- name: Install Playwright
run: npx playwright install --with-deps
- name: Build libraries
run: yarn build
- name: Build storybook
run: yarn build:storybook
- name: Serve Storybook and run tests
run: |
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server apps/storybook/dist --port 6006" \
"npx wait-on tcp:6006 && yarn workspace @designsystemet/storybook test-storybook"
38 changes: 38 additions & 0 deletions apps/storybook/.storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { TestRunnerConfig } from '@storybook/test-runner';
import { checkA11y, injectAxe } 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 = {
// Tags to include, exclude, or skip. These tags are defined as annotations in your story or meta.
tags: {
exclude: [],
},
async preVisit(page) {
await injectAxe(page);
},
async postVisit(page, context) {
/*
* Accessibility testing
*/
await checkA11y(
page,
'#storybook-root',
{
detailedReport: false,
detailedReportOptions: {
html: true,
},
verbose: false,
axeOptions: {},
},
false,
'v2',
);
},
};

export default config;
5 changes: 4 additions & 1 deletion apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"private": true,
"scripts": {
"dev": "storybook dev -p 6006",
"build": "storybook build -o ./dist"
"build": "storybook build -o ./dist",
"test-storybook": "test-storybook"
},
"author": "",
"license": "ISC",
Expand All @@ -29,10 +30,12 @@
"@storybook/manager-api": "^8.2.9",
"@storybook/react": "^8.2.9",
"@storybook/react-vite": "^8.2.9",
"@storybook/test-runner": "^0.19.1",
"@storybook/theming": "^8.2.9",
"@storybook/types": "^8.2.9",
"@types/react": "18.3.3",
"@types/react-dom": "^18.3.0",
"axe-playwright": "^2.0.2",
"remark-gfm": "^4.0.0",
"storybook": "^8.2.9"
}
Expand Down
Loading

0 comments on commit 79bdc51

Please sign in to comment.