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: allow axe to run in certain configurations of jsdom #3755

Merged
merged 4 commits into from
Oct 31, 2022
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
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be polyfills

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