Skip to content

Commit

Permalink
Merge pull request #210 from abhinaba-ghosh/feature/select-reporter
Browse files Browse the repository at this point in the history
Feature/select reporter
  • Loading branch information
BeataKr authored Feb 15, 2023
2 parents 14730d9 + 941c22d commit d160019
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ The `verbose` key is a boolean to whether to print the message `No accessibility

##### reporter (optional)

A class instance that implements the `Reporter` interface or values `default` and `v2`. Custom reporter instances can be supplied to override default reporting behaviour dictated by `DefaultTerminalReporter` set by the value `default`. `v2` is the new TerminalReporter inspired by the reports from [jest-axe](https://github.com/nickcolley/jest-axe).
A class instance that implements the `Reporter` interface or values `default`, `v2` and `html`. Custom reporter instances can be supplied to override default reporting behaviour dictated by `DefaultTerminalReporter` set by the value `default`. `v2` is the new TerminalReporter inspired by the reports from [jest-axe](https://github.com/nickcolley/jest-axe). `html` reporter will generate external HTML file.

Note! `html` reporter will disable printed to logs violations.

##### skipFailures (optional, defaults to false)

Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,17 @@ export const checkA11y = async (
context: ElementContext | undefined = undefined,
axeOptions: AxeOptions | undefined = undefined,
skipFailures: boolean = false,
reporter: Reporter | 'default' | 'v2' = 'default',
reporter: Reporter | 'default' | 'html' | 'v2' = 'default',
options: Options | undefined = undefined
): Promise<void> => {
const violations = await getViolations(page, context, axeOptions?.axeOptions)

if (violations.length > 0) {
await createHtmlReport({ results: { violations }, options } as CreateReport)
} else console.log("There were no violations to save in report");

const impactedViolations = getImpactedViolations(
violations,
axeOptions?.includedImpacts,
)

let reporterWithOptions: Promise<void> | Reporter | void
let reporterWithOptions: Promise<void> | Reporter | void | any

if (reporter === 'default') {
reporterWithOptions = new DefaultTerminalReporter(
Expand All @@ -127,13 +123,17 @@ export const checkA11y = async (
)
} else if (reporter === 'v2') {
reporterWithOptions = new TerminalReporterV2(axeOptions?.verbose ?? false)
} else if (reporter === 'html') {
if (violations.length > 0) {
await createHtmlReport({ results: { violations }, options } as CreateReport)
} else console.log("There were no violations to save in report");
} else {
reporterWithOptions = reporter
}

await reportViolations(impactedViolations, reporterWithOptions)
if (reporter !== 'html') await reportViolations(impactedViolations, reporterWithOptions)

if (reporter !== 'v2') testResultDependsOnViolations(impactedViolations, skipFailures)
if (reporter === 'v2' || reporter !== 'html') testResultDependsOnViolations(impactedViolations, skipFailures)
}

export { DefaultTerminalReporter }
2 changes: 1 addition & 1 deletion test/a11y.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('Playwright web page accessibility test using generated html report wit
},
},
},
true, 'default',
false, 'html',
{
outputDirPath: 'results',
outputDir: 'accessibility',
Expand Down

0 comments on commit d160019

Please sign in to comment.