Range.compareBoundaryPoints should throw error
Describe the bug
Range.compareBoundaryPoints should throw error if the compared ranges' boundary-point's are in different tree.
Documentation: Range.compareBoundaryPoints 2nd point:
If this’s root is not the same as sourceRange’s root, then throw a "WrongDocumentError" DOMException.
Reproduction
Repo to reproduce: compare-boundary-points-error
const text1 = document.createElement("text");
const text2 = document.createElement("text");
const range = new Range();
range.setStart(text1, 0);
const sourceRange = new Range();
sourceRange.setStart(text2, 0);
const position = range.compareBoundaryPoints(
Range.START_TO_START,
sourceRange,
); // shoud throw an error, since the text1 and text2 are in the different tree
console.log(position); // -1
System Info
System:
OS: Windows 11 10.0.22631
CPU: (12) x64 AMD Ryzen 5 5600 6-Core Processor
Memory: 19.36 GB / 31.89 GB
Binaries:
Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
bun: 1.1.10 - ~\.bun\bin\bun.EXE
Browsers:
Edge: Chromium (125.0.2535.51)
Internet Explorer: 11.0.22621.3527
npmPackages:
@vitest/coverage-v8: ^1.6.0 => 1.6.0
vite: ^5.2.10 => 5.2.10
vitest: ^1.6.0 => 1.6.0
Used Package Manager
npm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Hello @mozesstumpf. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.
The reproduction works fine in jsdom and chrome+browser mode. Both throw WrongDocumentError as expected.
The issue is only reproducible in happy-dom, it works fine in jsdom.
It looks like that the issue is rather related to the happy-dom than vitest, even though I'm not sure whether the Range API was implemented by vitest or happy-dom.
As it works on jsdom and browser mode, but not on happy-dom, I would say that this is an issue on their side. Vitest itself doesn't do anything related to these APIs.
I would recommend to open an issue on happy-dom.
Link to the happy-dom issue: https://github.com/capricorn86/happy-dom/issues/1462
Closing this as I don't see any reason to keep this open in Vitest.