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

Add p-queue to queue axe calls #6

Merged
merged 2 commits into from
Nov 28, 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
8 changes: 7 additions & 1 deletion AxeObserver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axeCore from 'axe-core'
import debounce from 'lodash.debounce'
import PQueue from 'p-queue'

// If requestIdleCallback is not supported, we fallback to setTimeout
// Ref: https://developers.google.com/web/updates/2015/08/using-requestidlecallback
Expand All @@ -9,6 +10,11 @@ const requestIdleCallback =
setTimeout(callback, 1)
}

// axe-core cannot be run concurrently. There are no plans to implement this
// functionality or a queue. Hence we use PQueue to queue calls ourselves.
// Ref: https://github.com/storybookjs/storybook/pull/4086
const axeQueue = new PQueue({ concurrency: 1 })

// The AxeObserver class takes a violationsCallback, which is invoked with an
// array of observed violations.
export default class AxeObserver {
Expand Down Expand Up @@ -82,7 +88,7 @@ export default class AxeObserver {
})
}
async _auditTargetNode(targetNode) {
const response = await axeCore.run(targetNode)
const response = await axeQueue.add(() => axeCore.run(targetNode))

const violationsToReport = response.violations.filter(violation => {
const filteredNodes = violation.nodes.filter(node => {
Expand Down
65 changes: 44 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "agnostic-axe",
"version": "1.1.0",
"version": "1.1.1",
"description": "Framework agnostic accessibility auditing with axe-core",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down Expand Up @@ -43,6 +43,7 @@
},
"dependencies": {
"axe-core": "^3.4.0",
"lodash.debounce": "^4.0.8"
"lodash.debounce": "^4.0.8",
"p-queue": "^6.2.1"
}
}