Skip to content

Commit

Permalink
Remove axeCoreConfiguration option in favor of axeCoreInstanceCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliette Pretot authored and jul-sh committed Dec 20, 2019
1 parent 965d3fa commit 0b57d7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
5 changes: 2 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import('https://unpkg.com/agnostic-axe@3').then(
The `AxeObserver` constructor takes two parameters:

- `violationsCallback` (required). A function that is invoked with an array of violations, as reported by [axe-core](https://github.com/dequelabs/axe-core). To log violations to the console, simply pass the `logViolations` function exported by this module.
- `options` (optional). An object with that supports the following configuration keys:
- `axeCoreConfiguration` (optional). [A configuration object for axe-core](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#api-name-axeconfigure). Overwrites the default configuration used by agnostic axe.
- `axeCoreInstanceCallback` (optional). A callback that is invoked with the [axe-core](https://github.com/dequelabs/axe-core) instance.
- `options` (optional`). An object with that supports the following configuration keys:
- `axeCoreInstanceCallback` (optional, defaults to `AxeObserver.applyDefaultAxeCoreConfig). Function that is invoked with the [axe-core](https://github.com/dequelabs/axe-core) instance used by AxeObserver.

The `AxeObserver.observe` method takes one parameter:

Expand Down
39 changes: 17 additions & 22 deletions src/AxeObserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import AuditQueue from './AuditQueue.mjs'
// The AxeObserver class takes a violationsCallback, which is invoked with an
// array of observed violations.
export default class AxeObserver {
static applyDefaultAxeCoreConfig = axeCore => {
axeCore.configure({
reporter: 'v2',
checks: [
{
id: 'color-contrast',
options: {
// Prevent axe from automatically scrolling
noScroll: true
}
}
]
})
}
constructor(
violationsCallback,
{
axeCoreConfiguration = {
reporter: 'v2',
checks: [
{
id: 'color-contrast',
options: {
// Prevent axe from automatically scrolling
noScroll: true
}
}
]
},
axeCoreInstanceCallback
} = {}
{ axeCoreInstanceCallback = AxeObserver.applyDefaultAxeCoreConfig } = {}
) {
if (typeof violationsCallback !== 'function') {
throw new Error(
Expand All @@ -44,13 +44,8 @@ export default class AxeObserver {
// AuditQueue sequentially runs audits when the browser is idle.
this._auditQueue = new AuditQueue()

// Allow for registering plugins etc
if (typeof axeCoreInstanceCallback === 'function') {
axeCoreInstanceCallback(axeCore)
}

// Configure axe
axeCore.configure(axeCoreConfiguration)
// Configure axeCore
axeCoreInstanceCallback(axeCore)
}
observe(targetNode) {
if (!targetNode) {
Expand Down

0 comments on commit 0b57d7f

Please sign in to comment.