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 nwsapi to v2.2.2 #60

Merged
merged 2 commits into from
Feb 17, 2024
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
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"bidi-js": "^1.0.3",
"css-tree": "^2.3.1",
"is-potential-custom-element-name": "^1.0.1",
"nwsapi": "^2.2.7"
"nwsapi": "2.2.2"
},
"devDependencies": {
"@types/css-tree": "^2.3.6",
Expand All @@ -42,13 +42,16 @@
"eslint-plugin-regexp": "^2.2.0",
"eslint-plugin-unicorn": "^51.0.1",
"happy-dom": "^13.3.8",
"jsdom": "24.0.0",
"jsdom": "^24.0.0",
"linkedom": "^0.16.8",
"mocha": "^10.3.0",
"sinon": "^17.0.1",
"typescript": "^5.3.3",
"wpt-runner": "^5.0.0"
},
"overrides": {
"nwsapi": "2.2.2"
},
"scripts": {
"bench": "node benchmark/bench.js",
"bench-sizzle": "node benchmark/bench-sizzle.js",
Expand Down
71 changes: 63 additions & 8 deletions test/jsdom-issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,77 @@ const jsdom = (str = '') => {
url: 'http://localhost/',
beforeParse: window => {
const domSelector = new DOMSelector(window);

const matches = domSelector.matches.bind(domSelector);
window.Element.prototype.matches = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.matches(selector, this);
return matches(selector, this);
};

const closest = domSelector.closest.bind(domSelector);
window.Element.prototype.closest = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.closest(selector, this);
return closest(selector, this);
};

const querySelector = domSelector.querySelector.bind(domSelector);
window.Document.prototype.querySelector = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelector(selector, this);
return querySelector(selector, this);
};
window.DocumentFragment.prototype.querySelector = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelector(selector, this);
return querySelector(selector, this);
};
window.Element.prototype.querySelector = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelector(selector, this);
return querySelector(selector, this);
};

const querySelectorAll = domSelector.querySelectorAll.bind(domSelector);
window.Document.prototype.querySelectorAll = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelectorAll(selector, this);
return querySelectorAll(selector, this);
};
window.DocumentFragment.prototype.querySelectorAll = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelectorAll(selector, this);
return querySelectorAll(selector, this);
};
window.Element.prototype.querySelectorAll = function (...args) {
if (!args.length) {
const msg = '1 argument required, but only 0 present.';
throw new window.TypeError(msg);
}
const [selector] = args;
return domSelector.querySelectorAll(selector, this);
return querySelectorAll(selector, this);
};
}
});
Expand Down Expand Up @@ -492,6 +500,53 @@ describe('jsdom issues tagged with `selectors` label', () => {
});
});

describe('#3544 - https://github.com/jsdom/jsdom/issues/3544', () => {
let document;
beforeEach(() => {
const dom = jsdom();
document = dom.window.document;
});
afterEach(() => {
document = null;
});

it('should get matched node(s)', () => {
const body = document.body;
const div = document.createElement('div');
const ul = document.createElement('ul');
const li = document.createElement('li');
ul.appendChild(li);
div.appendChild(ul);
body.appendChild(div);
const res1 = div.querySelectorAll('UL');
const res2 = div.querySelectorAll('ul');
const res3 = div.querySelectorAll('ul > li');
const res4 = div.querySelectorAll('UL > LI');
assert.deepEqual(res1, [ul], 'result1');
assert.deepEqual(res2, [ul], 'result2');
assert.deepEqual(res3, [li], 'result3');
assert.deepEqual(res4, [li], 'result4');
});

it('should get matched node(s)', () => {
const body = document.body;
const div = document.createElement('div');
const ul = document.createElement('ul');
const li = document.createElement('li');
ul.appendChild(li);
div.appendChild(ul);
body.appendChild(div);
const res1 = ul.matches('UL');
const res2 = ul.matches('ul');
const res3 = li.matches('ul > li');
const res4 = li.matches('UL > LI');
assert.isTrue(res1, 'result1');
assert.isTrue(res2, 'result2');
assert.isTrue(res3, 'result3');
assert.isTrue(res4, 'result4');
});
});

describe('#3666 - https://github.com/jsdom/jsdom/issues/3666', () => {
const html = `
<!doctype html>
Expand Down
Loading