Skip to content

Commit

Permalink
fix: allow axe to run in certain configurations of jsdom (#3755)
Browse files Browse the repository at this point in the history
* fix: allow axe to run in certain configurations of jsdom

* have eslint prevent

* remove

* more explicit
  • Loading branch information
straker committed Oct 31, 2022
1 parent d6b2144 commit b74c5d4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
20 changes: 18 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ module.exports = {
sourceType: 'module'
},
env: {
browser: true,
// do not access global window properties without going through window
browser: false,
es6: true
},
globals: {
Expand All @@ -95,14 +96,29 @@ module.exports = {
parserOptions: {
sourceType: 'module'
},
env: {},
env: {
browser: false
},
globals: {},
rules: {
'func-names': [2, 'as-needed'],
'prefer-const': 2,
'no-use-before-define': 'off'
}
},
{
// polyfills are mostly copy-pasted from sources so we don't control their styling
files: ['lib/core/utils/pollyfills.js'],
env: {
browser: false
},
rules: {
'func-names': 0,
'no-bitwise': 0,
curly: 0,
eqeqeq: 0
}
},
{
files: ['test/act-rules/**/*.js', 'test/aria-practices/**/*.js'],
env: {
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/color/get-background-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import reduceToElementsBelowFloating from '../dom/reduce-to-elements-below-float
* @return {Boolean}
*/
function isInlineDescendant(node, descendant) {
const CONTAINED_BY = Node.DOCUMENT_POSITION_CONTAINED_BY;
const CONTAINED_BY = window.Node.DOCUMENT_POSITION_CONTAINED_BY;
// eslint-disable-next-line no-bitwise
if (!(node.compareDocumentPosition(descendant) & CONTAINED_BY)) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/core/utils/dq-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function getSource(element) {
return '';
}
var source = element.outerHTML;
if (!source && typeof XMLSerializer === 'function') {
source = new XMLSerializer().serializeToString(element);
if (!source && typeof window.XMLSerializer === 'function') {
source = new window.XMLSerializer().serializeToString(element);
}
return truncate(source || '');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/utils/parse-crossorigin-stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function parseCrossOriginStylesheet(
importedUrls.push(url);

return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
const request = new window.XMLHttpRequest();
request.open('GET', url);

request.timeout = constants.preload.timeout;
Expand Down
5 changes: 2 additions & 3 deletions lib/core/utils/pollyfills.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
/*
These polyfills came directly from the ES Specification itself
Contained within:
Expand Down Expand Up @@ -348,8 +347,8 @@ if (!Array.prototype.flat) {

// linked from MDN docs on isConnected
// @see https://gist.github.com/eligrey/f109a6d0bf4efe3461201c3d7b745e8f
if (window.Node && !('isConnected' in Node.prototype)) {
Object.defineProperty(Node.prototype, 'isConnected', {
if (window.Node && !('isConnected' in window.Node.prototype)) {
Object.defineProperty(window.Node.prototype, 'isConnected', {
get() {
return (
!this.ownerDocument ||
Expand Down

0 comments on commit b74c5d4

Please sign in to comment.