fix(axe-core-4.2.0): replace usages of axe._tree with axe.setup #4223
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Details
axe-core
4.2.0 deprecated direct access to the internalaxe._tree
in favor of newaxe.setup
andaxe.teardown
APIs in dequelabs/axe-core#2738. This PR replaces our usage of the deprecated thing.The changes include:
getUniqueSelector
(and giving it unit tests, which it was missing)ScannerUtils
toAxeUtils
as part of its rewrite (it has no dependencies on theScanner
, andAxeUtils
is where all the other axe-internal usages live)window-initializer
to drop itsScannerUtils
depwithAxeSetup
wrapper for bothgetUniqueSelector
and unit tests to usewithAxeSetup
instead of manual_tree
manipulationMotivation
There are a few reasons we want to do this.
First, just as technical debt avoidance (avoiding dependency on a deprecated thing).
Second,
axe.teardown()
does more cleanup than we were previously doing ingetUniqueSelector
; this avoids the possibility ofgetUniqueSelector
leaking some invalid bit of cache data into a subsequent scan.Third, because
setup
contains an assertion that it hasn't already been called (eg, by axe itself while a scan is in progress), this improves our the behavior whengetUniqueSelector
is called while an axe scan is in progress. Practically speaking, this could happen if a user attempted to use the tab stops visualizer or the scoping feature's element selector while a scan is in progress. Previously, this would blindly overwrite axe's internal state while the scan was in progress, and was liable to cause silently incorrect scan results. With this change, the visualizer/selector operation will instead throw an error, and the scan will continue uninterrupted.I don't think it's super likely for users to hit this conflict in practice, but if a user did, I think a visualizer/selector failing and needing to be retried is vastly better than scan results being unpredictably inaccurate.
Context
Pull request checklist
yarn fastpass
yarn test
)<rootDir>/test-results/unit/coverage
fix:
,chore:
,feat(feature-name):
,refactor:
). SeeCONTRIBUTING.md
.