Skip to content

Commit 539e41b

Browse files
committed
fix($axe.run): Generate logs only if there are new violations
1 parent f53c67c commit 539e41b

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"build:unpkg": "rollup --config rollup.config.prod.js --format iife --file dist/vue-axe.min.js",
1414
"release": "standard-version",
1515
"test:e2e": "node_modules/.bin/cypress run --headless",
16-
"test:e2e:open": "node_modules/.bin/cypress open ",
16+
"test:e2e:open": "node_modules/.bin/cypress open",
1717
"project:publish": "git push --follow-tags origin master && npm publish",
1818
"deploy": "surge ./demo https://vue-axe.surge.sh/"
1919
},

Diff for: src/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axeCore from 'axe-core'
22
import debounce from 'lodash.debounce'
33
import merge from 'lodash.merge'
4-
import { checkAndReport, resetCache, resetLastNotification } from './utils'
4+
import { checkAndReport, draf, resetCache, resetLastNotification } from './utils'
55

66
export default function install (Vue, options) {
77
// Browser only
@@ -44,20 +44,18 @@ export default function install (Vue, options) {
4444
Vue.prototype.$axe = {
4545
run ({ clearConsole = options.clearConsoleOnUpdate, element = document } = {}) {
4646
this.clearConsole(clearConsole)
47-
if (!clearConsole) resetLastNotification()
48-
Vue.nextTick().then(() => checkAndReport(options, element))
47+
draf(() => checkAndReport(options, element))
4948
},
5049
plugins: axeCore.plugins,
5150
clearConsole (forceClear = false) {
5251
resetCache()
53-
5452
if (forceClear || options.clearConsoleOnUpdate) {
5553
console.clear()
5654
resetLastNotification()
5755
}
5856
},
5957
debounce: debounce(function () {
60-
this.run({ clearConsole: options.clearConsoleOnUpdate })
58+
this.run()
6159
}, 1000, { maxWait: 5000 })
6260
}
6361

@@ -75,5 +73,5 @@ export default function install (Vue, options) {
7573
}
7674
})
7775

78-
setTimeout(() => Vue.nextTick().then(() => checkAndReport(options, document)), options.delay)
76+
setTimeout(() => draf(() => checkAndReport(options, document)), options.delay)
7977
}

Diff for: src/utils.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function checkAndReport (options, node) {
1313

1414
axeCore.run(node || document, options.runOptions, (error, results) => {
1515
if (error) deferred.reject(error)
16-
if (!results) return
16+
if (results && !results.violations.length) return
1717
if (JSON.stringify(results.violations) === lastNotification) return
1818

1919
if (options.clearConsoleOnUpdate) {
@@ -61,6 +61,8 @@ export function resetLastNotification () {
6161
lastNotification = ''
6262
}
6363

64+
export const draf = (cb) => requestAnimationFrame(() => requestAnimationFrame(cb))
65+
6466
function sortViolations (violations) {
6567
let sorted = []
6668
impacts.forEach(impact => {

0 commit comments

Comments
 (0)