Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove axeCoreConfiguration option in favor of axeCoreInstanceCallback #19

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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@2').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