Skip to content

Commit

Permalink
Merge pull request #1 from lpelypenko/improveOutputOnNoViolations
Browse files Browse the repository at this point in the history
Improved output for no violations and added test
  • Loading branch information
lpelypenko authored Oct 27, 2020
2 parents a507a23 + 4bf5204 commit d219e1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export function prettyPrintAxeReport(report: SpecReportInput): void {
passes: report.passes,
url: report.url,
});
console.info(preparedData.violationsTotal);
// Print summary of violations as a table
if (preparedData.violationsSummaryTable.length !== 0) {
console.info(preparedData.violationsTotal);
if (!report.skipResultTable) {
console.table(preparedData.violationsSummaryTable);
}
Expand Down
10 changes: 7 additions & 3 deletions src/prepareReportData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function getWcagReference(tags: string[]): string {
* - detailed list of violations that could be printed as formatted text
* @param violations
* @param passes
* @param url
*/
export function prepareReportData({ violations, passes, url }: SpecReportInput): SpecPreparedData {
if (!violations) {
Expand All @@ -53,7 +54,9 @@ export function prepareReportData({ violations, passes, url }: SpecReportInput):
: '';
if (violations.length === 0) {
return {
violationsTotal: 'No accessibility violation were detected',
violationsTotal: `No accessibility violation were detected${
url ? ` for the ${url}` : ''
}`,
violationsSummaryTable: [],
violationsDetailsFormatted: '',
checksPassedSummary,
Expand Down Expand Up @@ -92,8 +95,9 @@ export function prepareReportData({ violations, passes, url }: SpecReportInput):
.join('\n')
);

return `${i +
1}. ${axeRuleId}\t${learnMore}\n${name}\n${summary}\n${wcagRef}\n${nodeDetails}\n`;
return `${
i + 1
}. ${axeRuleId}\t${learnMore}\n${name}\n${summary}\n${wcagRef}\n${nodeDetails}\n`;
})
.join('\n');

Expand Down
6 changes: 6 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('printAxeReport() test', () => {
skipResultTable: true,
});
});
it('no violations', async () => {
prettyPrintAxeReport({
violations: [],
url: 'www.example.com',
});
});
it('Verify throwing an error if violations are not passed', async () => {
expect(() => {
//@ts-ignore
Expand Down

0 comments on commit d219e1e

Please sign in to comment.