Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add cypress-axe test for homepage (#4362)
- Loading branch information
1 parent
1085177
commit 4ed686f
Showing
13 changed files
with
471 additions
and
46 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
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,4 @@ | ||
{ | ||
"baseUrl": "http://localhost:3000", | ||
"fixturesFolder": false | ||
} |
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,15 @@ | ||
import { checkAccessibility } from '../utils'; | ||
|
||
describe('Index', () => { | ||
it('has no accessibility issues detected by aXe', () => { | ||
cy.visit('/'); | ||
cy.injectAxe(); | ||
|
||
// 1. Check accessibility in default, light mode | ||
checkAccessibility(); | ||
|
||
// 2. Check accessibility in dark mode | ||
cy.contains('🌞').click(); | ||
checkAccessibility(); | ||
}); | ||
}); |
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,17 @@ | ||
/// <reference types="cypress" /> | ||
|
||
/** | ||
* @type {Cypress.PluginConfig} | ||
*/ | ||
module.exports = on => { | ||
on('task', { | ||
log(message) { | ||
console.log(message); | ||
return null; | ||
}, | ||
table(message) { | ||
console.table(message); | ||
return null; | ||
}, | ||
}); | ||
}; |
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 @@ | ||
import 'cypress-axe'; |
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 @@ | ||
import './commands'; |
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,28 @@ | ||
function terminalLog(violations) { | ||
cy.task( | ||
'log', | ||
`${violations.length} accessibility violation${ | ||
violations.length === 1 ? '' : 's' | ||
} detected`, | ||
); | ||
for (const violation of violations) { | ||
cy.task('log', JSON.stringify(violation, null, 4)); | ||
} | ||
|
||
cy.task( | ||
'table', | ||
violations.map(({ description, id, impact, nodes }) => ({ | ||
description, | ||
id, | ||
impact, | ||
nodes: nodes.length, | ||
})), | ||
); | ||
} | ||
|
||
export function checkAccessibility() { | ||
// Wait for any pending paints and ticks to clear | ||
cy.wait(500); | ||
|
||
cy.checkA11y(undefined, undefined, terminalLog); | ||
} |
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
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
Oops, something went wrong.