-
Notifications
You must be signed in to change notification settings - Fork 0
Integrate axe-playwright into storybook/test-runner #828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
aff522a
6ce0603
0445c5a
08ab053
e7e470a
caf33a0
99d5ac0
eb9c48e
77cfc42
35dd260
914678e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| const { getStoryContext } = require('@storybook/test-runner'); | ||
| const { injectAxe, checkA11y } = require('axe-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 preVisit(page) { | ||
| await injectAxe(page); | ||
| }, | ||
| 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; | ||
| } | ||
| await checkA11y( | ||
| page, | ||
| '#root', | ||
| { | ||
| detailedReport: true, | ||
| verbose: false, | ||
| }, | ||
| false, | ||
| 'v2' | ||
| ); | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,6 @@ const menu = ` | |
| }).outerHTML | ||
| } | ||
| </li> | ||
| <li role="separator"></li> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #829 |
||
| <li> | ||
| ${ | ||
| Button({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ breadCrumbsMenu.innerHTML = ` | |
| </svg> | ||
| </li>`; | ||
|
|
||
| export const header = document.createElement('header'); | ||
| export const header = document.createElement('div'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component is already wrapped in a header landmark, so it cannot have another header landmark inside of it. |
||
| header.innerHTML = ` | ||
| <div class="u-flex u-justify-between u-flex-wrap u-items-center u-margin-m-y"> | ||
| <div class="u-flex u-flex-wrap u-items-center"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,12 +28,9 @@ buttonList.classList.add( | |
| 'u-padding-s4-left' | ||
| ); | ||
|
|
||
| const listItem = document.createElement('li'); | ||
| listItem.classList.add('u-margin-s2-bottom', 'u-flex'); | ||
|
|
||
| const buttomComponent = (label) => | ||
| const buttonComponent = (label) => | ||
| Button({ | ||
| classname: ['u-justify-start'], | ||
| classname: ['u-justify-start', 'u-flex-grow-1'], | ||
| children: `<svg width="20" height="20" class="a-icon a-icon--m" aria-hidden="true" focusable="false"><use xlink:href="${icons}#icon-caret-right"></use></svg><span class="u-margin-s1-left">${label}</span>`, | ||
| colorVariant: ['transparent'], | ||
| }); | ||
|
|
@@ -47,9 +44,12 @@ const labels = [ | |
| 'Sales', | ||
| ]; | ||
|
|
||
| labels.forEach((label) => | ||
| buttonList.appendChild(listItem.appendChild(buttomComponent(label))) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cause |
||
| ); | ||
| labels.forEach((label) => { | ||
| const listItem = document.createElement('li'); | ||
| listItem.classList.add('u-margin-s2-bottom', 'u-flex'); | ||
| listItem.appendChild(buttonComponent(label)); | ||
| buttonList.appendChild(listItem); | ||
| }); | ||
|
|
||
| export const bottom = document.createElement('div'); | ||
| bottom.innerHTML = ` | ||
|
|
@@ -91,7 +91,6 @@ bottom.innerHTML = ` | |
| <li> | ||
| <a href="/" class="a-button a-button--transparent"> Privacy </a> | ||
| </li> | ||
| <li role="separator"></li> | ||
| <li> | ||
| <a href="/" class="a-button a-button--transparent"> Sign out </a> | ||
| </li> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aria-selectedis not allowed on normal buttons, so a tab role must be added. And then the button needs to we wrapped in a tablist because tabs must be children of tablists only, they cannot stand alone.