forked from pa11y/pa11y
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (43 loc) · 1.31 KB
/
index.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
// An example of running Pa11y on multiple URLS
// in parallel, with a configurable concurrency.
'use strict';
var async = require('async');
var pa11y = require('../..');
// Create a test instance with some default options
var test = pa11y({
// Log what's happening to the console
log: {
debug: console.log.bind(console),
error: console.error.bind(console),
info: console.log.bind(console)
}
});
// Define some URLs to test, and a concurrency
var urls = [
'http://www.google.com/',
'http://www.twitter.com/',
'http://github.com/'
];
var concurrency = 2; // Run two tests at a time
// Use the async library to create a queue. This accepts a
// function to handle the URLs, and a concurrency.
// https://github.com/caolan/async
var queue = async.queue(function(url, done) {
// The queue function will be called with each URL. We
// can then run the pa11y test function on them and call
// `done` when we're finished to free up the queue
test.run(url, function(error, results) {
if (error) {
return console.error(error.message);
}
console.log(results);
done();
});
}, concurrency);
// Add a function that is triggered when the queue
// drains (it runs out of URLs to process)
queue.drain = function() {
console.log('All done!');
};
// Lastly, push the URLs we wish to test onto the queue
queue.push(urls);