mirror of
https://github.com/kognise/water.css.git
synced 2026-01-22 13:07:05 +01:00
feat: run a11y checks with Promise.all
This commit is contained in:
parent
1f99994cf1
commit
035c0be3b9
1 changed files with 18 additions and 10 deletions
|
|
@ -18,34 +18,42 @@ const check = async (browser, theme) => {
|
||||||
page
|
page
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await page.close()
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
|
||||||
|
const log = (results, theme) => {
|
||||||
if (results.issues.length === 0) {
|
if (results.issues.length === 0) {
|
||||||
await page.close()
|
console.log(chalk`{blue ${theme} –} {green.bold No issues found!}`)
|
||||||
console.log(chalk`{green No issues found!}`)
|
return
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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}`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue