Skip to content

Commit 086b946

Browse files
feat: add Storybook deployment workflow and integrate accessibility testing
1 parent 2148e5b commit 086b946

7 files changed

Lines changed: 99 additions & 4 deletions

File tree

.github/workflows/cd.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CD - Deploy Storybook
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy-storybook:
10+
runs-on: ubuntu-latest
11+
environment:
12+
name: github-pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 22
27+
28+
- uses: bitovi/github-actions-storybook-to-github-pages@v1.0.3
29+
with:
30+
install_command: npm ci
31+
build_command: npm run build-storybook
32+
path: storybook-static
33+
checkout: false

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ jobs:
6262
badge-title: Virtual screenreader Tests
6363
path: reports/virtual-screenreader.xml
6464
reporter: jest-junit
65+
66+
- name: Build Storybook 📚
67+
run: npm run build-storybook
68+
- name: Start Storybook
69+
run: npm run storybook &
70+
- name: Wait for Storybook to be ready
71+
run: npx wait-on http://localhost:6006
72+
- name: Run Storybook a11y tests 🧪
73+
run: npm run test:storybook

.storybook/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @type { import('@storybook/react-vite').StorybookConfig } */
22
const config = {
33
'stories': ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
4-
'addons': ['@storybook/addon-essentials'],
4+
'addons': ['@storybook/addon-essentials', '@storybook/addon-a11y'],
55
'framework': {
66
'name': '@storybook/react-vite',
77
'options': {},

.storybook/preview.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import '../src/components/styles.css';
33
/** @type { import('@storybook/react').Preview } */
44
const preview = {
55
parameters: {
6+
a11y: { test: 'error', rules: [{ id: 'region', enabled: false }] },
67
controls: {
78
matchers: {
89
color: /(background|color)$/i,

.storybook/test-runner.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { injectAxe, checkA11y, configureAxe } from 'axe-playwright';
2+
import { getStoryContext } from '@storybook/test-runner';
3+
4+
/*
5+
* See https://storybook.js.org/docs/writing-tests/test-runner#test-hook-api
6+
* to learn more about the test-runner hooks API.
7+
*/
8+
const config = {
9+
async preVisit(page) {
10+
await injectAxe(page);
11+
},
12+
async postVisit(page, context) {
13+
// Get the entire context of a story, including parameters, args, argTypes, etc.
14+
const storyContext = await getStoryContext(page, context);
15+
16+
// Do not run a11y tests on disabled stories.
17+
if (storyContext.parameters?.a11y?.disable) {
18+
return;
19+
}
20+
21+
// Apply story-level a11y rules
22+
await configureAxe(page, {
23+
rules: storyContext.parameters?.a11y?.config?.rules,
24+
});
25+
26+
await checkA11y(page, 'body', {
27+
detailedReport: true,
28+
detailedReportOptions: {
29+
html: true,
30+
},
31+
});
32+
},
33+
};
34+
35+
export default config;

.storybook/vitest.setup.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { beforeAll } from 'vitest';
2+
import { setProjectAnnotations } from '@storybook/react';
3+
import * as projectAnnotations from './preview';
4+
import * as a11yAddonAnnotations from '@storybook/addon-a11y/preview';
5+
6+
// This is an important step to apply the right configuration when testing your stories.
7+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
8+
const project = setProjectAnnotations([
9+
projectAnnotations,
10+
a11yAddonAnnotations,
11+
]);
12+
13+
beforeAll(project.beforeAll);

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"preview": "vite preview",
1212
"storybook": "storybook dev -p 6006",
1313
"build-storybook": "storybook build",
14+
"test:storybook": "JEST_JUNIT_OUTPUT_DIR=reports JEST_JUNIT_OUTPUT_NAME=storybook.xml test-storybook --junit",
1415
"test:testing-library": "vitest --config ./vitest.config.js",
1516
"test:playwright": "PLAYWRIGHT_JUNIT_OUTPUT_DIR=reports PLAYWRIGHT_JUNIT_OUTPUT_NAME=playwright.xml playwright test -c playwright-ct.config.js --reporter=junit",
1617
"test:screenreader:virtual": "vitest --config ./vitest.virtual.config.js",
@@ -29,9 +30,12 @@
2930
"@guidepup/virtual-screen-reader": "^0.32.1",
3031
"@playwright/experimental-ct-react": "^1.52.0",
3132
"@playwright/test": "^1.52.0",
32-
"@storybook/addon-essentials": "^8.6.12",
33-
"@storybook/react": "^8.6.13",
34-
"@storybook/react-vite": "^8.6.13",
33+
"@storybook/addon-a11y": "^8.6.14",
34+
"@storybook/addon-essentials": "^8.6.14",
35+
"@storybook/react": "^8.6.14",
36+
"@storybook/react-vite": "^8.6.14",
37+
"@storybook/test": "^8.6.14",
38+
"@storybook/test-runner": "^0.22.0",
3539
"@testing-library/jest-dom": "^6.6.3",
3640
"@testing-library/react": "^16.3.0",
3741
"@testing-library/user-event": "^14.6.1",

0 commit comments

Comments
 (0)