-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
25 changed files
with
966 additions
and
2,574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
}; |
Oops, something went wrong.