Skip to content

Commit 8c5c81b

Browse files
author
Jan Morawietz
committed
feat: add custom result handler
1 parent 28db0b7 commit 8c5c81b

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/utils.js

+27-22
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,41 @@ export function checkAndReport (options, node) {
2222
console.clear()
2323
}
2424

25-
results.violations = results.violations.filter(result => {
26-
result.nodes = result.nodes.filter(node => {
27-
let key = node.target.toString() + result.id
28-
let retVal = (!cache[key])
29-
cache[key] = key
30-
return retVal
31-
})
32-
return (!!result.nodes.length)
33-
})
25+
options.customResultHandler ? options.customResultHandler(error, results) : standardResultHandler(error, results)
3426

35-
if (results.violations.length) {
36-
console.group('%cNew aXe issues', STYLE.head)
37-
results.violations.forEach(result => {
38-
let styl = IMPACT.hasOwnProperty(result.impact) ? IMPACT[result.impact] : IMPACT.minor
39-
console.groupCollapsed('%c%s: %c%s %s', STYLE[styl], result.impact, STYLE.defaultReset, result.help, result.helpUrl)
40-
result.nodes.forEach(function (node) {
41-
failureSummary(node, 'any')
42-
failureSummary(node, 'none')
43-
})
44-
console.groupEnd()
45-
})
46-
console.groupEnd()
47-
}
4827
deferred.resolve()
4928

5029
lastNotification = JSON.stringify(results.violations)
5130
})
5231
return deferred.promise
5332
}
5433

34+
const standardResultHandler = function(error, results) {
35+
results.violations = results.violations.filter(result => {
36+
result.nodes = result.nodes.filter(node => {
37+
let key = node.target.toString() + result.id
38+
let retVal = (!cache[key])
39+
cache[key] = key
40+
return retVal
41+
})
42+
return (!!result.nodes.length)
43+
})
44+
45+
if (results.violations.length) {
46+
console.group('%cNew aXe issues', STYLE.head)
47+
results.violations.forEach(result => {
48+
let styl = IMPACT.hasOwnProperty(result.impact) ? IMPACT[result.impact] : IMPACT.minor
49+
console.groupCollapsed('%c%s: %c%s %s', STYLE[styl], result.impact, STYLE.defaultReset, result.help, result.helpUrl)
50+
result.nodes.forEach(function (node) {
51+
failureSummary(node, 'any')
52+
failureSummary(node, 'none')
53+
})
54+
console.groupEnd()
55+
})
56+
console.groupEnd()
57+
}
58+
}
59+
5560
export function resetCache () {
5661
cache = {}
5762
}

0 commit comments

Comments
 (0)