forked from CosmicKenny/cosmic_crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wcagTester.js
32 lines (26 loc) · 932 Bytes
/
wcagTester.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
const chalk = require('chalk');
const pa11y = require('pa11y');
const htmlReporter = require('pa11y-reporter-html');
const fs = require('fs');
const util = require('util');
const writeFile = util.promisify(fs.writeFile);
const test = async (url, storage, reportName) => {
/*
- use Pa11y to load the {url} to scan for WCAG,
- save the WCAG report in {storage}/{reportName}.html
- save the WCAG screenshot in {storage}/{reportName}.jpg
*/
const results = await pa11y(url, {
wait: 1000,
timeout: 60000,
screenCapture: `${storage}/${reportName}.jpg`
});
const htmlResults = await htmlReporter.results(results);
const scanResult = await writeFile(`${storage}/${reportName}.html`, htmlResults).catch(err => {
console.log(err);
return err;
});
console.log(`${chalk.underline.blueBright(`${storage}/${reportName}.html`)} is saved.`);
return scanResult;
};
module.exports.wcagTester = test;