Detecting accessibility issues on CI with cypress-axe
Unless we check the accessibility of our pages every time we change them, it’s to easy to introduce regressions. Therefore, we should test accessibility during our Continuous Integration (CI) checks.
Cypress-axe allows us to do exactly that, and it’s a good place to do that in Cypress because we already render all the pages in our end-to-end tests and run them during CI.
Install cypress-axe (assuming we already have Cypress installed and configured on our project):
Import the commands, add to the cypress/support/index.js:
Update the plugins file, cypress/plugins/index.js:
We need this for printing the results in the terminal.
Add a custom Cypress command, cypress/support/commands.js:
This command runs cypress-axe checkA11y method with a custom violation callback function that prints a list of violations to the terminal, and can be chained to queries.