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:
@@ -18,34 +18,42 @@ const check = async (browser, theme) => {
|
|||||||
page
|
page
|
||||||
})
|
})
|
||||||
|
|
||||||
if (results.issues.length === 0) {
|
|
||||||
await page.close()
|
await page.close()
|
||||||
console.log(chalk`{green No issues found!}`)
|
return results
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
for (const issue of results.issues) {
|
||||||
console.log()
|
console.log()
|
||||||
console.log(chalk`{red Error:} ${issue.message}`)
|
|
||||||
console.log(chalk`{gray -> ${issue.code}}`)
|
console.log(chalk`{gray -> ${issue.code}}`)
|
||||||
console.log(chalk`{gray -> ${issue.selector}}`)
|
console.log(chalk`{gray -> ${issue.selector}}`)
|
||||||
console.log(chalk`{gray -> ${issue.context}}`)
|
console.log(chalk`{gray -> ${issue.context}}`)
|
||||||
}
|
}
|
||||||
|
console.log()
|
||||||
await page.close()
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const go = async () => {
|
const go = async () => {
|
||||||
try {
|
try {
|
||||||
const browser = await puppeteer.launch()
|
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()
|
console.log()
|
||||||
const darkResult = await check(browser, 'dark')
|
|
||||||
|
|
||||||
await browser.close()
|
await browser.close()
|
||||||
if (lightResult || darkResult) process.exit(1)
|
|
||||||
|
const errorsFound = lightResults.issues.length || darkResults.issues.length
|
||||||
|
if (errorsFound) process.exit(1)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log()
|
console.log()
|
||||||
console.log(chalk`{red An unexpected error occured!} ${error.message}`)
|
console.log(chalk`{red An unexpected error occured!} ${error.message}`)
|
||||||
|
Reference in New Issue
Block a user