Skip to content

Commit

Permalink
Add option to override timeouts for larger scans
Browse files Browse the repository at this point in the history
  • Loading branch information
Finholt committed Oct 30, 2020
1 parent 73dedb1 commit 384ef88
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ package = "netlify-plugin-a11y"

# resultMode = "warn" # is "error" by default

# timeout = 60000 # in milliseconds; is 30000 by default

# # Developer only
# debugMode = true # extra logging for plugin developers
```
Expand Down
2 changes: 2 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ inputs:
required: false
- name: resultMode
default: error
- name: timeout
default: 30000
- name: debugMode
default: false
- name: testMode
Expand Down
3 changes: 2 additions & 1 deletion plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const pluginCore = require('./pluginCore');

module.exports = {
async onPostBuild({
inputs: { checkPaths, ignoreDirectories, resultMode, debugMode },
inputs: { checkPaths, ignoreDirectories, resultMode, timeout, debugMode },
constants: { PUBLISH_DIR },
utils: { build }
}) {
Expand All @@ -24,6 +24,7 @@ module.exports = {
const results = await pluginCore.runPa11y({
htmlFilePaths,
build,
timeout,
debugMode
});

Expand Down
8 changes: 4 additions & 4 deletions plugin/pluginCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const pa11y = require('pa11y');
const readdirp = require('readdirp')
const { isDirectory, isFile } = require('path-type')

exports.runPa11y = async function({ htmlFilePaths, build, testMode, debugMode }) {
let results = await Promise.all(htmlFilePaths.map(htmlFilePath => runPa11yOnFile(htmlFilePath, build)));
exports.runPa11y = async function({ htmlFilePaths, build, timeout, testMode, debugMode }) {
let results = await Promise.all(htmlFilePaths.map(htmlFilePath => runPa11yOnFile(htmlFilePath, build, timeout)));
results = results
.filter((res) => res.issues.length)
.map((res) =>
Expand All @@ -25,9 +25,9 @@ exports.runPa11y = async function({ htmlFilePaths, build, testMode, debugMode })
return flattenedResults;
};

const runPa11yOnFile = async function(htmlFilePath, build) {
const runPa11yOnFile = async function(htmlFilePath, build, timeout) {
try {
return await pa11y(htmlFilePath)
return await pa11y(htmlFilePath, {timeout, chromeLaunchConfig: {timeout}})
} catch (error) {
build.failBuild(`pa11y failed`, { error })
}
Expand Down
3 changes: 2 additions & 1 deletion tests/runPa11y/this.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const pluginCore = require('../../plugin/pluginCore.js');
test('runPa11y works', async () => {
const results = await pluginCore.runPa11y({
htmlFilePaths: [path.join(__dirname, 'publishDir/index.html')],
build: { failBuild() {} }
build: { failBuild() {} },
timeout: 30000
});
expect(results).toMatchSnapshot();
});

0 comments on commit 384ef88

Please sign in to comment.