-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pa11y reporters do not output to console when used with Pa11y CI #174
Comments
After thinking about this a little, if pa11y-ci were updated to simply write the value returned from a reporter to stdout, as pa11y does (in most cases), then it would do the same for all analyzed files. The results could be piped to a file, but the result wouldn't be valid for the given format (excluding An alternative proposal - create a new reporter that's essentially a shim for using any pa11y reporter:
For the pa11y reporters:
|
It's not much but I took the JSON reporter and changet it to wrap the pa11y HTML reporter: 'use strict';
const fs = require('fs');
const { resolve, isAbsolute, dirname } = require('path');
const pa11yHtmlReporter = require('pa11y/lib/reporters/html');
function writeReport(fileName, data) {
try {
const dirPath = dirname(fileName);
if (!(fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory())) {
fs.mkdirSync(dirPath, { recursive: true });
}
fs.writeFileSync(fileName, data);
} catch (error) {
console.error(`Unable to write ${fileName}`);
console.error(error);
}
}
function resolveFile(fileName) {
if (typeof fileName !== 'string') {
return null;
}
return isAbsolute(fileName) ? fileName : resolve(process.cwd(), fileName);
}
module.exports = function htmlReporter(options = {}) {
const fileName = resolveFile(options.fileName);
return {
results(report) {
return pa11yHtmlReporter.results(report).then((html) => {
// If reporter options specify an output file, write to file.
// Otherwise, write to console.
if (fileName) {
writeReport(fileName, html);
} else {
console.log(html);
}
});
},
};
}; Config: {
"defaults": {
"reporters": [
"cli",
["./pa11y-ci-html-reporter.js", { "fileName": "./pa11y-cli-report.html" }]
]
}
}
It now writes its output either to a file or console. |
@langalex if you're just looking for an HTML reporter for pa11y-ci, you can try https://www.npmjs.com/package/pa11y-ci-reporter-html, which produces a report for each page as well as a summary (for full disclosure, it's my npm package) |
Thanks. I ended up creating my own Markdown report so I could attach it to a PR check summary here on GitHub. |
When
pa11y
loads reporters, it wraps the reporter functions so that any output from any reporter function is written toconsole
(here). That logic is missing frompa11y-ci
(it should probably be here). So, whenpa11y
reporters are used withpa11y-ci
, any reporters that returns a value expecting it to externally be written to console have their output lost. This includes thecli
,csv
,html
, andtsv
reporters. Thejson
reporter is not impacted since it directly writes its output.The dedicated
pa11y-ci
reporters handle their own output so are not effected.The text was updated successfully, but these errors were encountered: