axe-playwright
Advanced tools
Comparing version 1.1.1 to 1.1.3
@@ -49,5 +49,5 @@ "use strict"; | ||
}, [context, options]); | ||
const { includedImpacts, detailedReport = true } = options || {}; | ||
const { includedImpacts, detailedReport = false, detailedReportOptions = { html: false }, } = options || {}; | ||
const violations = getImpactedViolations(axeResults.violations, includedImpacts); | ||
printViolationTerminal(violations, detailedReport); | ||
printViolationTerminal(violations, detailedReport, !!detailedReportOptions.html); | ||
testResultDependsOnViolations(violations, skipFailures); | ||
@@ -74,17 +74,23 @@ }); | ||
const describeViolations = (violations) => { | ||
const nodeViolations = []; | ||
violations.map(({ nodes }) => { | ||
nodes.forEach((node) => { | ||
const failure = node.any[0].message; | ||
nodeViolations.push({ | ||
target: JSON.stringify(node.target), | ||
html: node.html, | ||
impact: node.impact, | ||
violation: failure, | ||
}); | ||
const aggregate = {}; | ||
violations.map(({ nodes }, index) => { | ||
nodes.forEach(({ target, html }) => { | ||
const key = JSON.stringify(target) + html; | ||
if (aggregate[key]) { | ||
aggregate[key].violations.push(index); | ||
} | ||
else { | ||
aggregate[key] = { | ||
target: JSON.stringify(target), | ||
html, | ||
violations: [index], | ||
}; | ||
} | ||
}); | ||
}); | ||
return nodeViolations; | ||
return Object.values(aggregate).map(({ target, html, violations }) => { | ||
return { target, html, violations: JSON.stringify(violations) }; | ||
}); | ||
}; | ||
const printViolationTerminal = (violations, detailedReport) => { | ||
const printViolationTerminal = (violations, detailedReport, includeHtml) => { | ||
const violationData = violations.map(({ id, impact, description, nodes }) => { | ||
@@ -102,3 +108,11 @@ return { | ||
if (detailedReport) { | ||
const nodeViolations = describeViolations(violations); | ||
const nodeViolations = describeViolations(violations).map(({ target, html, violations }) => { | ||
if (!includeHtml) { | ||
return { | ||
target, | ||
violations, | ||
}; | ||
} | ||
return { target, html, violations }; | ||
}); | ||
// per node | ||
@@ -105,0 +119,0 @@ console.table(nodeViolations); |
@@ -9,3 +9,7 @@ import { ElementContext, ImpactValue, RunOptions } from 'axe-core' | ||
export type Options = { includedImpacts?: ImpactValue[] } & axeOptionsConfig | ||
export type Options = { | ||
includedImpacts?: ImpactValue[] | ||
detailedReport?: boolean | ||
detailedReportOptions?: { html?: boolean } | ||
} & axeOptionsConfig | ||
@@ -12,0 +16,0 @@ declare module 'axe-core' { |
{ | ||
"name": "axe-playwright", | ||
"version": "1.1.1", | ||
"version": "1.1.3", | ||
"description": "Custom Playwright commands to inject axe-core and test for a11y", | ||
@@ -20,3 +20,3 @@ "main": "dist/index.js", | ||
"prerelease": "npm run build", | ||
"release": "npm cache clean --force && npm version patch && npm publish" | ||
"release": "npm cache clean --force && npm version patch && npm publish --force" | ||
}, | ||
@@ -23,0 +23,0 @@ "peerDependencies": { |
@@ -100,3 +100,3 @@ ![logo](./docs/logo.png) | ||
The keys consist of [those accepted by `axe.run`'s options argument](https://www.deque.com/axe/documentation/api-documentation/#parameters-axerun) as well as custom `includedImpacts` and `detailedReport` keys. | ||
The keys consist of [those accepted by `axe.run`'s options argument](https://www.deque.com/axe/documentation/api-documentation/#parameters-axerun) as well as custom `includedImpacts`, `detailedReport`, and `detailedReportOptions` keys. | ||
@@ -110,4 +110,10 @@ The `includedImpacts` key is an array of strings that map to `impact` levels in violations. Specifying this array will only include violations where the impact matches one of the included values. Possible impact values are "minor", "moderate", "serious", or "critical". | ||
The `detailedReport` key is a boolean that defaults to `true`. In addition to the summary it prints out a per node report and the violations to be able to hone in on the failures. | ||
The `detailedReport` key is a boolean whether to print the more detailed report `detailedReportOptions` is an object with the shape | ||
``` | ||
{ | ||
html?: boolean // include the full html for the offending nodes | ||
} | ||
``` | ||
##### skipFailures (optional, defaults to false) | ||
@@ -114,0 +120,0 @@ |
@@ -6,11 +6,10 @@ import { Page } from 'playwright' | ||
AxeResults, | ||
Check, | ||
ElementContext, | ||
ImpactValue, | ||
Locale, | ||
Result, | ||
Rule, | ||
RunOptions, | ||
NodeResult, | ||
Result, | ||
Spec, | ||
Check, | ||
Rule, | ||
Locale, | ||
} from 'axe-core' | ||
@@ -31,2 +30,3 @@ | ||
detailedReport?: boolean | ||
detailedReportOptions?: { html?: boolean } | ||
} & axeOptionsConfig | ||
@@ -78,3 +78,7 @@ | ||
const { includedImpacts, detailedReport = true } = options || {} | ||
const { | ||
includedImpacts, | ||
detailedReport = false, | ||
detailedReportOptions = { html: false }, | ||
} = options || {} | ||
const violations: Result[] = getImpactedViolations( | ||
@@ -85,3 +89,7 @@ axeResults.violations, | ||
printViolationTerminal(violations, detailedReport) | ||
printViolationTerminal( | ||
violations, | ||
detailedReport, | ||
!!detailedReportOptions.html, | ||
) | ||
testResultDependsOnViolations(violations, skipFailures) | ||
@@ -128,23 +136,34 @@ } | ||
html: string | ||
impact: ImpactValue | undefined | ||
violation: string | ||
violations: string | ||
} | ||
const describeViolations = (violations: Result[]) => { | ||
const nodeViolations: NodeViolation[] = [] | ||
interface Aggregate { | ||
[key: string]: { | ||
target: string | ||
html: string | ||
violations: number[] | ||
} | ||
} | ||
violations.map(({ nodes }) => { | ||
nodes.forEach((node: NodeResult) => { | ||
const failure = node.any[0].message | ||
const describeViolations = (violations: Result[]): NodeViolation[] => { | ||
const aggregate: Aggregate = {} | ||
nodeViolations.push({ | ||
target: JSON.stringify(node.target), | ||
html: node.html, | ||
impact: node.impact, | ||
violation: failure, | ||
}) | ||
violations.map(({ nodes }, index) => { | ||
nodes.forEach(({ target, html }) => { | ||
const key = JSON.stringify(target) + html | ||
if (aggregate[key]) { | ||
aggregate[key].violations.push(index) | ||
} else { | ||
aggregate[key] = { | ||
target: JSON.stringify(target), | ||
html, | ||
violations: [index], | ||
} | ||
} | ||
}) | ||
}) | ||
return nodeViolations | ||
return Object.values(aggregate).map(({ target, html, violations }) => { | ||
return { target, html, violations: JSON.stringify(violations) } | ||
}) | ||
} | ||
@@ -155,2 +174,3 @@ | ||
detailedReport: boolean, | ||
includeHtml: boolean, | ||
) => { | ||
@@ -170,3 +190,13 @@ const violationData = violations.map(({ id, impact, description, nodes }) => { | ||
if (detailedReport) { | ||
const nodeViolations = describeViolations(violations) | ||
const nodeViolations = describeViolations(violations).map( | ||
({ target, html, violations }) => { | ||
if (!includeHtml) { | ||
return { | ||
target, | ||
violations, | ||
} | ||
} | ||
return { target, html, violations } | ||
}, | ||
) | ||
// per node | ||
@@ -173,0 +203,0 @@ console.table(nodeViolations) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20261
364
187
9