Skip to content

Commit

Permalink
Add WCAG PR check (#274)
Browse files Browse the repository at this point in the history
Add a GH workflow to check for WCAG violations. If the check fails, the PR will be blocked from merging into main. There are some WCAG violations that we ignore, namely color contrast failures on stories where components are in a "loading" state. Using config options, that rule is disabled for those particular stories. To get the automated WCAG checks, Storybook has to be running while the `npm run wcag` command is run.

Note, Jest had to be downgraded to v27 to work with `@storybook/test-runner`. But, it looks like they will be adding support for v28 shortly (storybookjs/test-runner#154), so we should be able to upgrade again soon. In the meantime, we haven't been using any features from v28, so the downgrade didn't affect any tests.

Also, the Snyk checks are failing, but the new license and one of new vulnerabilities are both approved by legal in Juliann's [PR](#264 (comment)). The other new vulnerability is also introduced only through Storybook, so we wouldn't be susceptible to it.

J=SLAP-2289
TEST=auto

See that the check runs as expected on this PR and passes.
  • Loading branch information
nmanu1 authored Aug 5, 2022
1 parent f3c4ad0 commit d734620
Show file tree
Hide file tree
Showing 25 changed files with 966 additions and 2,574 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/wcag_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: WCAG tests

on:
pull_request:
branches:
- main

jobs:
call_wcag_test:
uses: yext/slapshot-reusable-workflows/.github/workflows/wcag_test.yml@v1
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
build_script: ./tests/scripts/start-storybook.sh
6 changes: 2 additions & 4 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './index.css';
import { SearchCoreDecorator } from '../tests/__fixtures__/core/SearchCore';
import { runOnly } from './wcagConfig';

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
Expand All @@ -12,10 +13,7 @@ export const parameters = {
},
a11y: {
options: {
runOnly: {
type: 'tag',
values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']
}
runOnly
}
},
options: {
Expand Down
29 changes: 29 additions & 0 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { injectAxe, checkA11y } from 'axe-playwright';
import { Page } from 'playwright-core';
import { runOnly } from './wcagConfig';

/**
* See https://storybook.js.org/docs/react/writing-tests/test-runner#test-hook-api-experimental
* to learn more about the test-runner hooks API.
*/
const renderFunctions = {
async preRender(page: Page) {
await injectAxe(page);
},
async postRender(page: Page, context) {
await checkA11y(page, '#root', {
axeOptions: {
runOnly,
rules: {
'color-contrast': { enabled: context.name !== 'Loading' }
},
},
detailedReport: true,
detailedReportOptions: {
html: true,
},
});
},
};

export default renderFunctions;
6 changes: 6 additions & 0 deletions .storybook/wcagConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { axeOptionsConfig } from 'axe-playwright';

export const runOnly: axeOptionsConfig['axeOptions']['runOnly'] = {
type: 'tag',
values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']
};
Loading

0 comments on commit d734620

Please sign in to comment.