forked from kognise/water.css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accessibility.js
55 lines (45 loc) · 1.36 KB
/
accessibility.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const pa11y = require('pa11y')
const chalk = require('chalk')
const puppeteer = require('puppeteer')
const check = async (browser, theme) => {
console.log(chalk`{bold Checking {blue ${theme}} theme...}`)
const page = await browser.newPage()
page.emulateMediaFeatures([
{ name: 'prefers-color-scheme', value: theme }
])
const results = await pa11y('./out/docs/index.html', {
ignore: [
'WCAG2AA.Principle3.Guideline3_2.3_2_2.H32.2' // Ignore "this form does not contain a submit button"
],
browser,
page
})
if (results.issues.length === 0) {
await page.close()
console.log(chalk`{green No issues found!}`)
return false
}
for (const issue of results.issues) {
console.log()
console.log(chalk`{red Error:} ${issue.message}`)
console.log(chalk`{gray -> ${issue.code}}`)
console.log(chalk`{gray -> ${issue.selector}}`)
console.log(chalk`{gray -> ${issue.context}}`)
}
await page.close()
return true
}
const go = async () => {
try {
const browser = await puppeteer.launch()
const lightResult = await check(browser, 'light')
console.log()
const darkResult = await check(browser, 'dark')
await browser.close()
if (lightResult || darkResult) process.exit(1)
} catch (error) {
console.log()
console.log(chalk`{red An unexpected error occured!} ${error.message}`)
}
}
go()