-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate axe-core/playwright into storybook/test-runner
- Loading branch information
1 parent
0b33bd1
commit aff522a
Showing
3 changed files
with
2,693 additions
and
56 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,35 @@ | ||
// TODO: try to make axe-playwright work or uninstall | ||
const { injectAxe, checkA11y, configureAxe } = require('axe-playwright'); | ||
const { getStoryContext } = require('@storybook/test-runner'); | ||
const { AxeBuilder } = require('@axe-core/playwright'); | ||
/* | ||
* See https://storybook.js.org/docs/writing-tests/test-runner#test-hook-api | ||
* to learn more about the test-runner hooks API. | ||
*/ | ||
module.exports = { | ||
async postVisit(page, context) { | ||
// Get the entire context of a story, including parameters, args, argTypes, etc. | ||
const storyContext = await getStoryContext(page, context); | ||
|
||
// Do not run a11y tests on disabled stories. | ||
if (storyContext.parameters?.a11y?.disable) { | ||
return; | ||
} | ||
|
||
const results = await new AxeBuilder({ page }).options({ | ||
// those rules fail for every story | ||
rules: { | ||
"region": { "enabled": false }, | ||
"landmark-one-main": { "enabled": false }, | ||
"page-has-heading-one": { "enabled": false } | ||
} | ||
}).analyze(); | ||
|
||
if (results.violations.length > 0) { | ||
const storyId = `'${storyContext.title} ${storyContext.name}' (id: ${storyContext.id})` | ||
console.error(`Story ${storyId} did not pass axe-core checks.\n\n`, JSON.stringify(results.violations, null, 2)); | ||
|
||
throw `Story ${storyId} did not pass axe-core checks. See test error logs for details.` | ||
} | ||
}, | ||
}; |
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
Oops, something went wrong.