diff --git a/plugin/index.js b/plugin/index.js index b93e243..d57a4c0 100644 --- a/plugin/index.js +++ b/plugin/index.js @@ -22,6 +22,7 @@ module.exports = { } const results = await pluginCore.runPa11y({ htmlFilePaths, + build, debugMode }); diff --git a/plugin/pluginCore.js b/plugin/pluginCore.js index 9d30b55..909aa47 100644 --- a/plugin/pluginCore.js +++ b/plugin/pluginCore.js @@ -4,8 +4,8 @@ const pa11y = require('pa11y'); const readdirp = require('readdirp') const { isDirectory, isFile } = require('path-type') -exports.runPa11y = async function({ htmlFilePaths, testMode, debugMode }) { - let results = await Promise.all(htmlFilePaths.map(pa11y)); +exports.runPa11y = async function({ htmlFilePaths, build, testMode, debugMode }) { + let results = await Promise.all(htmlFilePaths.map(htmlFilePath => runPa11yOnFile(htmlFilePath, build))); results = results .filter((res) => res.issues.length) .map((res) => @@ -25,6 +25,14 @@ exports.runPa11y = async function({ htmlFilePaths, testMode, debugMode }) { return flattenedResults; }; +const runPa11yOnFile = async function(htmlFilePath, build) { + try { + return await pa11y(htmlFilePath) + } catch (error) { + build.failBuild(`pa11y failed`, { error }) + } +} + exports.generateFilePaths = async function({ fileAndDirPaths, // array, mix of html and directories PUBLISH_DIR, diff --git a/tests/runPa11y/this.test.js b/tests/runPa11y/this.test.js index f0daf30..e6cfb4c 100644 --- a/tests/runPa11y/this.test.js +++ b/tests/runPa11y/this.test.js @@ -5,7 +5,8 @@ const path = require('path'); const pluginCore = require('../../plugin/pluginCore.js'); test('runPa11y works', async () => { const results = await pluginCore.runPa11y({ - htmlFilePaths: [path.join(__dirname, 'publishDir/index.html')] + htmlFilePaths: [path.join(__dirname, 'publishDir/index.html')], + build: { failBuild() {} } }); expect(results).toMatchSnapshot(); });