aboutsummaryrefslogtreecommitdiffstats
path: root/accessibility.js
diff options
context:
space:
mode:
authorkj_sh6042026-02-14 12:39:43 -0500
committerkj_sh6042026-02-14 12:39:43 -0500
commit44e5a55736c4ff99d404441936b055483ed9c42d (patch)
treebf22343ade74a79f18b44ea39449903d7501e70d /accessibility.js
fork: initial commit, derived from water.css (d950cbc)
Diffstat (limited to 'accessibility.js')
-rw-r--r--accessibility.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/accessibility.js b/accessibility.js
new file mode 100644
index 0000000..5fb3f8f
--- /dev/null
+++ b/accessibility.js
@@ -0,0 +1,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()