From 657ebe4abd3a697a7d4e70d24ffe096e1e06a6e2 Mon Sep 17 00:00:00 2001 From: BeataKr Date: Mon, 13 Feb 2023 12:11:28 +0100 Subject: [PATCH 1/3] select reporter --- src/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 377fbf5..fd07420 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 => { 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 | Reporter | void + let reporterWithOptions: Promise | Reporter | void | any if (reporter === 'default') { reporterWithOptions = new DefaultTerminalReporter( @@ -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 } From 997c22d2d116a2a546a6776817db52dfe496877c Mon Sep 17 00:00:00 2001 From: BeataKr Date: Mon, 13 Feb 2023 12:21:14 +0100 Subject: [PATCH 2/3] readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11cc45e..461b88f 100644 --- a/README.md +++ b/README.md @@ -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) From 941c22dd699a5f9558037ecc8bdaf4a9d77a42c9 Mon Sep 17 00:00:00 2001 From: BeataKr Date: Mon, 13 Feb 2023 14:09:52 +0100 Subject: [PATCH 3/3] html --- test/a11y.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/a11y.spec.ts b/test/a11y.spec.ts index fb28855..b97cbb1 100644 --- a/test/a11y.spec.ts +++ b/test/a11y.spec.ts @@ -188,7 +188,7 @@ describe('Playwright web page accessibility test using generated html report wit }, }, }, - true, 'default', + false, 'html', { outputDirPath: 'results', outputDir: 'accessibility',