Created
May 18, 2016 19:17
-
-
Save rowanmanning/cc5606c43030a9a064b8f7f9318db4a7 to your computer and use it in GitHub Desktop.
Example of running Pa11y in parallel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of running Pa11y in parallel. Now that I found | |
// this I realise it should definitely be in the examples | |
// in the repo! | |
// | |
// You'll need to install `async` and `pa11y`, probs in a | |
// package.json. This isn't perfect, might need some | |
// tweaking. Also runs in Node.js 4+ because I'm far too | |
// used to typing `const` and arrow functions now. | |
'use strict'; | |
const createQueue = require('async').queue; | |
const pa11y = require('pa11y'); | |
// Change the concurrency here to run more tests in parallel | |
const concurrency = 2; | |
const urls = [ | |
'http://www.google.com/', | |
'http://www.twitter.com/', | |
'http://www.github.com/' | |
]; | |
// Create a Pa11y test runner | |
const pa11yTest = pa11y({ | |
// your default options for all URLs | |
}); | |
// Create our queue | |
const queue = createQueue(processUrl, concurrency); | |
queue.drain = queueDrained; | |
queue.push(urls); // you could also add them individually | |
// Process a URL that was passed into the queue | |
function processUrl (url, done) { | |
pa11yTest.run(url, (error, results) => { | |
// FYI ignoring errors for now, you might want to log these somewhere | |
if (!error) { | |
const errorCount = results.filter(result => result.type === 'error').length; | |
console.log(`Finished testing ${url}: ${errorCount} errors`); | |
// ...or something more interesting | |
} | |
done(); | |
}); | |
} | |
// Called when everything's finished | |
function queueDrained () { | |
console.log('All done!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rowanmanning Hey nicely done!
What's the maximum
concurrency
do you thinkpa11y
can handle?