Skip to content

Commit

Permalink
fix(is-visible): do not error if window.Node does not exist (#3168)
Browse files Browse the repository at this point in the history
* fix(is-visible): do not error if window.Node does not exist

* circle

* Update test/test-virtual-rules.js

Co-authored-by: Wilco Fiers <[email protected]>

Co-authored-by: Wilco Fiers <[email protected]>
  • Loading branch information
straker and WilcoFiers authored Sep 28, 2021
1 parent ad4b165 commit 4046087
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ jobs:
- run: npm run build
- run: npm run test:locales

# Test virtual rules
test_virtual_rules:
<<: *defaults
<<: *unix_box
steps:
- checkout
- <<: *restore_dependency_cache_unix
- run: npm run build
- run: npm run test:virtual-rules

# Run the test suite for nightly builds.
test_nightly:
<<: *defaults
Expand Down Expand Up @@ -262,6 +272,9 @@ workflows:
- test_locales:
requires:
- test_unix
- test_virtual_rules:
requires:
- test_unix
- build_api_docs:
requires:
- test_unix
Expand All @@ -279,6 +292,7 @@ workflows:
- test_win
- test_examples
- test_locales
- test_virtual_rules
- build_api_docs
- test_rule_help_version
- test_node
Expand All @@ -293,6 +307,7 @@ workflows:
- test_unix
- test_examples
- test_locales
- test_virtual_rules
- build_api_docs
filters:
branches:
Expand All @@ -304,6 +319,7 @@ workflows:
- test_unix
- test_examples
- test_locales
- test_virtual_rules
- build_api_docs
- test_rule_help_version
- test_node
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/dom/is-visible.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function isVisible(el, screenReader, recursed) {
el = vNode ? vNode.actualNode : el;

const cacheName = '_isVisible' + (screenReader ? 'ScreenReader' : '');
const { DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE } = window.Node;
const { DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE } = window.Node ?? {};
const nodeType = vNode ? vNode.props.nodeType : el.nodeType;
const nodeName = vNode ? vNode.props.nodeName : el.nodeName.toLowerCase();

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"test:act": "karma start test/act-mapping/karma.config.js",
"test:act:debug": "npm run test:act -- --no-single-run --browsers=Chrome",
"test:locales": "mocha test/test-locales.js",
"test:virtual-rules": "mocha test/test-virtual-rules.js",
"test:rule-help-version": "mocha test/test-rule-help-version.js",
"test:node": "mocha test/node/*.js",
"version": "echo \"use 'npm run release' to bump axe-core version\" && exit 1",
Expand Down
23 changes: 23 additions & 0 deletions test/test-virtual-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var path = require('path');
var assert = require('chai').assert;
var glob = require('glob');
var axe = require('../axe');

var files = glob.sync(path.join(__dirname, 'integration/virtual-rules/*.js'));

before(function() {
global.axe = axe;
global.assert = assert;
});

after(function() {
delete global.axe;
delete global.assert;
});

describe('virtual-rule node tests', function() {
files.forEach(function(file) {
// load the test file and run with global axe and assert now defined
require(file);
});
});

0 comments on commit 4046087

Please sign in to comment.