-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpa11y-reporter-junit.js
43 lines (35 loc) · 1.15 KB
/
pa11y-reporter-junit.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
// ./pa11y-reporter-junit.js
// Copied from https://github.com/macieklewkowicz/pa11y-reporter-junit and modified it to work with pa11y-ci
const builder = require('junit-report-builder');
const fs = require('fs');
module.exports = function (options) {
const fileName = options.fileName
return {
// add test results to the report
results(results) {
// Create a test suite
const suite = builder.testSuite().name(results.pageUrl);
if (results.issues.length > 0) {
results.issues.forEach(issue => {
suite.testCase()
.className(issue.code)
.name(`[${results.pageUrl}] ${issue.selector}`)
.failure(`${issue.message}\n\nContext: ${issue.context}`);
});
} else {
// Identify passing test for a given URL if there are no accessibility errors.
suite.testCase()
.className(results.pageUrl)
.name('No accessibility errors');
}
},
// also store errors
error(error, url) {
},
// write to a file
afterAll() {
const data = builder.build();
return fs.promises.writeFile(fileName, data, 'utf8');
}
}
};