-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Tests: Add basic a11 verification for the editor code using aXe #10695
Conversation
package.json
Outdated
@@ -181,7 +182,7 @@ | |||
"publish:dev": "npm run build:packages && lerna publish --npm-tag next", | |||
"publish:prod": "npm run build:packages && lerna publish", | |||
"test": "concurrently \"npm run lint && npm run test-unit\" \"npm run test-mobile\"", | |||
"pretest-e2e": "concurrently \"./bin/reset-e2e-tests.sh\" \"npm run build\"", | |||
"pretest-e2e": "concurrently \"./bin/reset-e2e-tests.sh\"", |
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.
I need to revert it, it's painful to build for every run when hacking :)
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.
Maybe we need an option to disable it! 😆
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.
Maybe we need an option to disable it! 😆
It would be a nice addition. I've worked around this myself by copying, editing, and re-running the subcommand that triggers after the build, but it's not pretty 😅
e.g.
JEST_PUPPETEER_CONFIG=test/e2e/puppeteer.config.js npx wp-scripts test-unit-js --config test/e2e/jest.config.json --runInBand "test/e2e/specs/navigable-toolbar.test.js"
My very naive try to fix violations: diff --git a/packages/editor/src/components/default-block-appender/index.js b/packages/editor/src/components/default-block-appender/index.js
index afabf7c50..3a7fa5fd7 100644
--- a/packages/editor/src/components/default-block-appender/index.js
+++ b/packages/editor/src/components/default-block-appender/index.js
@@ -51,7 +51,6 @@ export function DefaultBlockAppender( {
<div data-root-client-id={ rootClientId || '' } className="editor-default-block-appender">
<BlockDropZone rootClientId={ rootClientId } layout={ layout } />
<input
- role="button"
aria-label={ __( 'Add block' ) }
className="editor-default-block-appender__content"
type="text"
diff --git a/packages/editor/src/components/post-title/index.js b/packages/editor/src/components/post-title/index.js
index 718784b7b..7e252a879 100644
--- a/packages/editor/src/components/post-title/index.js
+++ b/packages/editor/src/components/post-title/index.js
@@ -115,7 +115,7 @@ class PostTitle extends Component {
'mod+shift+z': this.redirectHistory,
} }
>
- <label htmlFor={ `post-title-${ instanceId }` } className="screen-reader-text">
+ <label htmlFor={ `post-title-${ instanceId }` }>
{ decodedPlaceholder || __( 'Add title' ) }
</label>
<Textarea |
We can use |
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.
So a nicer reporter would definitely be good here! Marcy's seems good, I guess we need to make our own reporter for that? (Hey, maybe we could publish it for others to use!)
I'm curious why role="button"
was used for that text field. It seems fine to remove.
What does removing screen-reader-text
className
do to the visuals of that component? I'd imagine it changes it...
package.json
Outdated
@@ -181,7 +182,7 @@ | |||
"publish:dev": "npm run build:packages && lerna publish --npm-tag next", | |||
"publish:prod": "npm run build:packages && lerna publish", | |||
"test": "concurrently \"npm run lint && npm run test-unit\" \"npm run test-mobile\"", | |||
"pretest-e2e": "concurrently \"./bin/reset-e2e-tests.sh\" \"npm run build\"", | |||
"pretest-e2e": "concurrently \"./bin/reset-e2e-tests.sh\"", |
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.
Maybe we need an option to disable it! 😆
test/e2e/specs/a11y.test.js
Outdated
@@ -18,6 +23,23 @@ describe( 'a11y', () => { | |||
await newPost(); | |||
} ); | |||
|
|||
it( 'passes aXe Javascript Accessibility API checks', async () => { |
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.
Typo: Javascript -> JavaScript 😄
@tofumatt I'd recommend to have a read at the related PR and issue, see #5742 / #4829 or maybe ask around could help answer your question. Seems that for technical reasons the block appender must be an input field:
However, it gets activated with a
I know this is, in a way, against the spec see #4829 (comment) but I think giving proper feedback to users is more important than an error thrown by a static analysis tool that can't evaluate the reasons behind it. That said, if you can change the appender to a real |
Sorry, I'm just revisiting this now because I think it's a useful tool to add for further work on the repo. I'd integrated a better reporter that worked with jest and did some tweaks to ignore the button failure... but then my Mac went weird and my Gutenberg repo was deleted. 😱 Sounds like the button test failure should be ignored, thanks for the context @afercia 👍 I'll take a look at the label issue, try to recreate my test suite work, and then we should get this merged. It's a handy thing to have 😄 |
@tofumatt sure thing, be my guest. I'd love to see this merged. You can ping me when it's ready for review. By the way, I thought that we might want to make all elements with |
@@ -18,6 +23,23 @@ describe( 'a11y', () => { | |||
await newPost(); | |||
} ); | |||
|
|||
it( 'passes aXe JavaScript Accessibility API checks', async () => { | |||
const handle = await page.evaluateHandle( ` |
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.
We've now got an axe-puppeteer
for this, and we hope to get it working today (at WordCamp).
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.
Awesome, as far as I can see it contains many useful helpers. That will make everything easier.
Happy WordCamp contributor day! This patch introduces accessibility testing using [`axe-puppeteer`](https://github.com/dequelabs/axe-puppeteer). Each one of the existing E2E tests now runs `AxePuppeteer#analyze()` on the relevant portion(s) of the DOM and outputs the returned a11y violations to stderr. In time, as these accessibility problems are fixed, the logging could be replaced with assertions, ensuring no "new" problems are introduced into the codebase. This patch is similar to WordPress#10695, but uses a more complete a11y testing tool and does not introduce new test failures.
Let's close in favor of #12743 🎉 |
Description
Still needs some nice way to print violations or simply fix them :)
How has this been tested?
Screenshots
Types of changes
Checklist: