1
0
mirror of https://github.com/kognise/water.css.git synced 2025-08-13 16:44:58 +02:00

feat: run a11y checks with Promise.all

This commit is contained in:
Jonas Kuske
2020-05-31 09:05:21 +02:00
parent 1f99994cf1
commit 035c0be3b9

View File

@@ -18,34 +18,42 @@ const check = async (browser, theme) => {
page
})
if (results.issues.length === 0) {
await page.close()
console.log(chalk`{green No issues found!}`)
return false
return results
}
const log = (results, theme) => {
if (results.issues.length === 0) {
console.log(chalk`{blue ${theme} } {green.bold No issues found!}`)
return
}
console.log()
console.log(chalk`{blue ${theme} } {red.bold Errors found:}`)
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
console.log()
}
const go = async () => {
try {
const browser = await puppeteer.launch()
const lightResult = await check(browser, 'light')
const [lightResults, darkResults] = await Promise.all([check(browser, 'light'), check(browser, 'dark')])
console.log()
log(lightResults, '☀ Light Theme')
log(darkResults, '🌙 Dark Theme')
console.log()
const darkResult = await check(browser, 'dark')
await browser.close()
if (lightResult || darkResult) process.exit(1)
const errorsFound = lightResults.issues.length || darkResults.issues.length
if (errorsFound) process.exit(1)
} catch (error) {
console.log()
console.log(chalk`{red An unexpected error occured!} ${error.message}`)