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

fix(run): cleanup globals if set from context #2387

Merged
merged 6 commits into from
Jul 20, 2020
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
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ jobs:
- <<: *restore_dependency_cache_unix
- run: npm run test:rule-help-version

# Test node API
test_node:
<<: *defaults
<<: *unix_box
steps:
- checkout
- <<: *restore_dependency_cache_unix
- run: npm run build
- run: npm run test:node

# Release a "next" version
next_release:
<<: *defaults
Expand Down Expand Up @@ -208,6 +218,9 @@ workflows:
- test_rule_help_version:
requires:
- test_unix
- test_node:
requires:
- test_unix
# Hold for approval
- hold:
type: approval
Expand All @@ -218,6 +231,7 @@ workflows:
- test_locales
- build_api_docs
- test_rule_help_version
- test_node
filters:
branches:
only:
Expand All @@ -242,6 +256,7 @@ workflows:
- test_locales
- build_api_docs
- test_rule_help_version
- test_node
- hold
filters:
branches:
Expand Down
10 changes: 9 additions & 1 deletion lib/core/public/run-rules.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import Context from '../base/context';
import cache from '../base/cache';

// Clean up after resolve / reject
function cleanup() {
if (cache.get('globalDocumentSet')) {
document = null;
}
if (cache.get('globalWindowSet')) {
window = null;
}

axe._memoizedFns.forEach(fn => fn.clear());
axe._cache.clear();
cache.clear();
axe._tree = undefined;
axe._selectorData = undefined;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/core/public/run.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getReporter } from './reporter';
import cache from '../base/cache';

function isContext(potential) {
'use strict';
Expand Down Expand Up @@ -102,10 +103,12 @@ function run(context, options, callback) {
}

if (!hasDoc) {
cache.set('globalDocumentSet', true);
document = context.ownerDocument;
}

if (!hasWindow) {
cache.set('globalWindowSet', true);
window = document.defaultView;
}
}
Expand Down
Loading