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

feat(setup/teardown): add functions to setup and teardown axe-core internal data, deprecate axe._tree #2738

Merged
merged 2 commits into from
Jan 12, 2021

Conversation

straker
Copy link
Contributor

@straker straker commented Jan 7, 2021

New functions for setup up and teardown of axe-core internal data axe._tree and caches. As we're returning the tree now that is created, we are deprecating axe._tree in favor of the return from axe.setup

const rootNode = axe.setup();
// use rootNode instead of axe._tree

Closes issue: #2570

@straker straker requested a review from a team as a code owner January 7, 2021 21:02
lib/core/public/setup.js Show resolved Hide resolved
lib/core/public/setup.js Show resolved Hide resolved
lib/core/public/teardown.js Show resolved Hide resolved
@straker straker changed the title feat(setup/teardown): add functions to setup and teardown axe-core internal data feat(setup/teardown): add functions to setup and teardown axe-core internal data, deprecate axe._tree Jan 8, 2021
@straker straker merged commit 9d19f24 into develop Jan 12, 2021
@straker straker deleted the setup-teardown branch January 12, 2021 17:00
dbjorge added a commit to microsoft/accessibility-insights-web that referenced this pull request May 19, 2021
#### Details

`axe-core` 4.2.0 deprecated direct access to the internal `axe._tree` in favor of new `axe.setup` and `axe.teardown` APIs in dequelabs/axe-core#2738. This PR replaces our usage of the deprecated thing.

The changes include:

* Rewriting `getUniqueSelector` (and giving it unit tests, which it was missing)
* Moving it from `ScannerUtils` to `AxeUtils` as part of its rewrite (it has no dependencies on the `Scanner`, and `AxeUtils` is where all the other axe-internal usages live)
    * As a result of this, updated `window-initializer` to drop its `ScannerUtils` dep
* Creating a `withAxeSetup` wrapper for both `getUniqueSelector` and unit tests to use
* Updating a bunch of unit tests (mostly of our custom checks/rules) to use `withAxeSetup` instead of manual `_tree` manipulation
* Adding an end to end test page for custom widgets (tests for the custom widgets checks were impacted, so I wanted to make sure I exercised the checks during my manual validation of the PR)

##### Motivation

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 in `getUniqueSelector`; this avoids the possibility of `getUniqueSelector` 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 when `getUniqueSelector` 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

<!-- Are there any parts that you've intentionally left out-of-scope for a later PR to handle? -->

<!-- Were there any alternative approaches you considered? What tradeoffs did you consider? -->

#### Pull request checklist
<!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox -->
- [n/a] Addresses an existing issue: #0000
- [x] Ran `yarn fastpass`
- [x] Added/updated relevant unit test(s) (and ran `yarn test`)
- [x] Verified code coverage for the changes made. Check coverage report at: `<rootDir>/test-results/unit/coverage`
- [x] PR title *AND* final merge commit title both start with a semantic tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See `CONTRIBUTING.md`.
- [n/a] (UI changes only) Added screenshots/GIFs to description above
- [n/a] (UI changes only) Verified usability with NVDA/JAWS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants