Skip to content

Commit b6317e9

Browse files
committed
feat(checkAndReport): Add the checked component name in log title
1 parent 672f261 commit b6317e9

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

Diff for: docs/guide/api.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ To execute the `$axe.run` method to check manually your document or any desired
1212
| ------------- | ------------------------ | ----------------------------------
1313
| clearConsole | Boolean | The same as `clearConsoleOnUpdate`
1414
| element | Document or HTMLElement | `document`
15+
| label | Strong | `Run manually`
1516

1617
```js
1718
methods: {
1819
axeRun() {
1920
this.$axe.run({
2021
clearConsole: true,
21-
element: this.$el // or document, document.querySelector('.selector'), ...
22+
element: this.$el, // or document, document.querySelector('.selector'), ...
23+
label: 'Logo component'
2224
})
2325
}
2426
}

Diff for: src/audit.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let lastNotification = ''
77
const deferred = {}
88
const impacts = [...axeCore.constants.impact].reverse()
99

10-
export function checkAndReport (options, node) {
10+
export function checkAndReport (options, node, label) {
1111
const deferred = createDeferred()
1212
style = { ...options.style }
1313

@@ -20,14 +20,14 @@ export function checkAndReport (options, node) {
2020
console.clear()
2121
}
2222

23-
options.customResultHandler ? options.customResultHandler(error, results) : standardResultHandler(error, results)
23+
options.customResultHandler ? options.customResultHandler(error, results) : standardResultHandler(error, results, label)
2424
deferred.resolve()
2525
lastNotification = JSON.stringify(results.violations)
2626
})
2727
return deferred.promise
2828
}
2929

30-
const standardResultHandler = function (errorInfo, results) {
30+
const standardResultHandler = function (errorInfo, results, label) {
3131
results.violations = results.violations.filter(result => {
3232
result.nodes = result.nodes.filter(node => {
3333
const key = node.target.toString() + result.id
@@ -40,7 +40,7 @@ const standardResultHandler = function (errorInfo, results) {
4040

4141
if (results.violations.length) {
4242
const violations = sortViolations(results.violations)
43-
console.group('%cNew axe issues', style.head)
43+
console.group(`%cAxe issues ${label ? '- ' + label : ''}`, style.head)
4444
violations.forEach(result => {
4545
console.groupCollapsed('%c%s%c %s %s %c%s', style[result.impact || 'minor'], result.impact, style.title, result.help, '\n', style.url, result.helpUrl)
4646
result.nodes.forEach(node => {

Diff for: src/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export default function install (Vue, options) {
1919

2020
// vue-axe methods in Vue Instance
2121
Vue.prototype.$axe = {
22-
run ({ clearConsole = options.clearConsoleOnUpdate, element } = {}) {
22+
run ({ clearConsole = options.clearConsoleOnUpdate, element, label } = {}) {
2323
clear(clearConsole, options)
24-
draf(() => checkAndReport(options, element))
24+
draf(() => checkAndReport(options, element, (label || 'Run manually')))
2525
},
2626
plugins: axeCore.plugins
2727
}
@@ -30,8 +30,9 @@ export default function install (Vue, options) {
3030
if (!options.auto) return
3131

3232
const checkWithDebounce = debounce(function () {
33+
const componentsName = this.$options.name || ''
3334
resetCache()
34-
draf(() => checkAndReport(options, this.$el))
35+
draf(() => checkAndReport(options, this.$el, componentsName))
3536
}, 1000, { maxWait: 5000 })
3637

3738
// Rechecking when updating specific component
@@ -46,5 +47,5 @@ export default function install (Vue, options) {
4647
})
4748

4849
// First check
49-
setTimeout(() => draf(() => checkAndReport(options, document)), options.delay)
50+
setTimeout(() => draf(() => checkAndReport(options, document, 'App')), options.delay)
5051
}

0 commit comments

Comments
 (0)