vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Range.compareBoundaryPoints should throw error

Open mozesstumpf opened this issue 1 year ago • 4 comments

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

mozesstumpf avatar May 29 '24 10:05 mozesstumpf

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.

github-actions[bot] avatar May 29 '24 11:05 github-actions[bot]

The reproduction works fine in jsdom and chrome+browser mode. Both throw WrongDocumentError as expected.

AriPerkkio avatar May 29 '24 11:05 AriPerkkio

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.

mozesstumpf avatar May 29 '24 20:05 mozesstumpf

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.

AriPerkkio avatar May 31 '24 10:05 AriPerkkio

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.

sheremet-va avatar Oct 02 '24 11:10 sheremet-va