Skip to content

Commit

Permalink
feat: add custom result handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Morawietz committed Apr 20, 2020
1 parent 28db0b7 commit 8c5c81b
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,41 @@ export function checkAndReport (options, node) {
console.clear()
}

results.violations = results.violations.filter(result => {
result.nodes = result.nodes.filter(node => {
let key = node.target.toString() + result.id
let retVal = (!cache[key])
cache[key] = key
return retVal
})
return (!!result.nodes.length)
})
options.customResultHandler ? options.customResultHandler(error, results) : standardResultHandler(error, results)

if (results.violations.length) {
console.group('%cNew aXe issues', STYLE.head)
results.violations.forEach(result => {
let styl = IMPACT.hasOwnProperty(result.impact) ? IMPACT[result.impact] : IMPACT.minor
console.groupCollapsed('%c%s: %c%s %s', STYLE[styl], result.impact, STYLE.defaultReset, result.help, result.helpUrl)
result.nodes.forEach(function (node) {
failureSummary(node, 'any')
failureSummary(node, 'none')
})
console.groupEnd()
})
console.groupEnd()
}
deferred.resolve()

lastNotification = JSON.stringify(results.violations)
})
return deferred.promise
}

const standardResultHandler = function(error, results) {
results.violations = results.violations.filter(result => {
result.nodes = result.nodes.filter(node => {
let key = node.target.toString() + result.id
let retVal = (!cache[key])
cache[key] = key
return retVal
})
return (!!result.nodes.length)
})

if (results.violations.length) {
console.group('%cNew aXe issues', STYLE.head)
results.violations.forEach(result => {
let styl = IMPACT.hasOwnProperty(result.impact) ? IMPACT[result.impact] : IMPACT.minor
console.groupCollapsed('%c%s: %c%s %s', STYLE[styl], result.impact, STYLE.defaultReset, result.help, result.helpUrl)
result.nodes.forEach(function (node) {
failureSummary(node, 'any')
failureSummary(node, 'none')
})
console.groupEnd()
})
console.groupEnd()
}
}

export function resetCache () {
cache = {}
}
Expand Down

0 comments on commit 8c5c81b

Please sign in to comment.