-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PoC of automated axe testing * fixing a11y bugs guidelines pages * Adds a11y tests to test command * adding a11y script * adding docs * fixing logging for yarn * catching errors in puppeteer setup to fail builds * experimenting with docker * retest * one step forward * deps * trial run * trial run * Revert "trial run" This reverts commit f0c8f9f. * user * fix typo * bypass webpack loader cache * DEBUG * env changes * sandbox trial * move to script file Co-authored-by: Greg Thompson <[email protected]>
- Loading branch information
1 parent
1343725
commit 68299f4
Showing
13 changed files
with
367 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const chalk = require('chalk'); | ||
const puppeteer = require('puppeteer'); | ||
const { AxePuppeteer } = require('axe-puppeteer'); | ||
|
||
const docsPages = async (root, page) => { | ||
let links = [ | ||
root, | ||
...(await page.$$eval('nav a', anchors => anchors.map(a => a.href))), | ||
]; | ||
|
||
links = links.splice(0, 9); | ||
|
||
return links; | ||
}; | ||
|
||
const printResult = result => | ||
console.log(`[${result.id}]: ${result.description} | ||
Help: ${chalk.blue(result.helpUrl)} | ||
Elements: | ||
- ${result.nodes.map(node => node.target).join('\n - ')}`); | ||
|
||
(async () => { | ||
let totalViolationsCount = 0; | ||
let root = 'http://localhost:9999/'; | ||
let browser; | ||
let page; | ||
|
||
try { | ||
browser = await puppeteer.launch({ args: ['--no-sandbox'] }); | ||
page = await browser.newPage(); | ||
|
||
await page.setBypassCSP(true); | ||
} catch (e) { | ||
console.log(chalk.red('Failed to setup puppeteer')); | ||
console.log(e); | ||
process.exit(1); | ||
} | ||
|
||
try { | ||
await page.goto(root); | ||
} catch (e) { | ||
root = 'http://localhost:8030/'; | ||
try { | ||
await page.goto(root); | ||
} catch (e) { | ||
console.log( | ||
chalk.red( | ||
'No local server found. Expecting localhost:9999 or localhost:8030 to resolve.' | ||
) | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
const links = await docsPages(root, page); | ||
|
||
for (const link of links) { | ||
await page.goto(link); | ||
|
||
const { violations } = await new AxePuppeteer(page) | ||
.disableRules('color-contrast') | ||
.exclude(['figure[role="figure"']) // excluding figure[role="figure"] the duplicatory role is there for ie11 support | ||
.analyze(); | ||
|
||
if (violations.length > 0) { | ||
totalViolationsCount += violations.length; | ||
|
||
const pageName = link.length > 24 ? link.substr(2) : 'the home page'; | ||
console.log(chalk.red(`Errors on ${pageName}`)); | ||
} | ||
|
||
violations.forEach(result => { | ||
printResult(result); | ||
}); | ||
} | ||
|
||
await page.close(); | ||
await browser.close(); | ||
|
||
if (totalViolationsCount > 0) { | ||
const errorsCount = chalk.red( | ||
`${totalViolationsCount} accessibility errors` | ||
); | ||
|
||
console.log(`${errorsCount} | ||
Install axe for Chrome or Firefox to debug: | ||
Chrome: https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd | ||
Firefox: https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/`); | ||
process.exit(1); | ||
} else { | ||
console.log(chalk.green('axe found no accessibility errors!')); | ||
} | ||
})(); |
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,18 @@ | ||
const { execSync } = require('child_process'); | ||
|
||
execSync('docker pull zenato/puppeteer', { | ||
stdio: 'inherit', | ||
}); | ||
/* eslint-disable-next-line no-multi-str */ | ||
execSync("docker run \ | ||
-i --rm --cap-add=SYS_ADMIN --volume=$(pwd):/app --workdir=/app \ | ||
-e GIT_COMMITTER_NAME=test -e GIT_COMMITTER_EMAIL=test -e HOME=/tmp \ | ||
--user=$(id -u):$(id -g) \ | ||
zenato/puppeteer \ | ||
bash -c 'npm config set spin false \ | ||
&& /opt/yarn*/bin/yarn \ | ||
&& npm run test \ | ||
&& npm run start-test-server-and-a11y-test \ | ||
&& npm run build'", { | ||
stdio: 'inherit', | ||
}); |
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.