Skip to content

Commit

Permalink
fix(run): cleanup globals if set from context (#2387)
Browse files Browse the repository at this point in the history
* fix(run): cleanup globals if set from context

* test node

* build first

* Update test/node/jsdom.js

Co-authored-by: Stephen Mathieson <me@stephenmathieson.com>

* Update test/node/jsdom.js

Co-authored-by: Stephen Mathieson <me@stephenmathieson.com>

Co-authored-by: Stephen Mathieson <me@stephenmathieson.com>
  • Loading branch information
straker and stephenmathieson authored Jul 20, 2020
1 parent e48c1eb commit d5b6931
Show file tree
Hide file tree
Showing 6 changed files with 738 additions and 1 deletion.
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

0 comments on commit d5b6931

Please sign in to comment.