This repository has been archived by the owner on Dec 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
a11y.test.js
70 lines (63 loc) · 1.59 KB
/
a11y.test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const pa11y = require('pa11y')
const baseUrl = 'http://localhost:3004'
const options = {
log: {
debug: console.log,
error: console.error,
info: console.log,
},
chromeLaunchConfig: {
args: ['--no-sandbox'], // pass sandbox flag for ci
},
hideElements: '.canada-flag',
ignore: ['WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.Span.Name'],
}
const registerActions = [
'set field #fullName to John Doe',
'click element main button',
]
/*--------------------------------------------*
* List of urls we want to visit
*--------------------------------------------*/
const visit = [
{ url: '/' },
{ url: '/register', actions: registerActions },
{ url: '/calendar' },
{ url: '/review' },
{ url: '/confirmation' },
{ url: '/confirmation/error' },
{ url: '/cancel' },
{ url: '/privacy' },
{ url: '/error' },
{ url: '/404' },
{ url: '/500' },
]
async function run() {
try {
const results = await Promise.all(
visit.map(page => {
return pa11y(baseUrl + page['url'], {
...options,
...{ actions: page['actions'] ? page['actions'] : [] },
})
}),
)
let issues = []
results.map(result => {
if (result && result.issues && result.issues.length >= 1) {
console.log(result)
issues.push(result)
}
})
if (issues.length >= 1) {
//process.exit(issues)
const count = issues.length
throw new Error(`Found ${count} page(s) with issues`)
}
} catch (error) {
// Output an error if it occurred
console.error('\n\n' + error.message + '\n\n')
process.exit(1)
}
}
run()