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

regression 0.12.7: window.Audio is undefined in environment: jsdom #1358

Closed
6 tasks done
sapphi-red opened this issue May 23, 2022 · 3 comments · Fixed by #1443
Closed
6 tasks done

regression 0.12.7: window.Audio is undefined in environment: jsdom #1358

sapphi-red opened this issue May 23, 2022 · 3 comments · Fixed by #1443

Comments

@sapphi-red
Copy link
Contributor

Describe the bug

window.Audio was not undefined below Vitest v0.12.6.
It is now undefined in Vitest v0.12.7+.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-gg5jqy?file=test%2Fbasic.test.ts&initialPath=__vitest__

System Info

stackblitz
Vitest 0.12.9 / 0.12.7 / 0.12.6 / 0.12.5

Used Package Manager

npm

Validations

@sionzee
Copy link

sionzee commented Jun 6, 2022

Same issue here, window._document is no longer accessible and therefore I cannot use implSymbol in tests.

@sheremet-va
Copy link
Member

Same issue here, window._document is no longer accessible and therefore I cannot use implSymbol in tests.

Why do you need private properties? We can allow some of them, if they are generally acceptable by the community.

@sionzee
Copy link

sionzee commented Jun 8, 2022

When you import the implSymbol from the package, then the value is different compared to the environment in the tests. (defacto implSymbol !== implSymbol)

JSDOM has a bug somewhere, so when you need to update a selection in the document, then nothing happens because it thinks the Range is created from a different document. I hacked this by using the _document variable:

const implSymbol = Object.getOwnPropertySymbols(window._document)[0]
const prototype = Object.getPrototypeOf(window.getSelection())
prototype.addRange = function (range) {
  window.getSelection()[implSymbol]._associateRange(range)
}

https://github.com/jsdom/jsdom/blob/04f6c13f4a4d387c7fc979b8f62c6f68d8a0c639/lib/jsdom/living/selection/Selection-impl.js#L87
Here you can see, range._root === implForWrapper(this._globalObject._document) and this condition is never satisfied due the implSymbol.

This issue is not related to Vitest, it was happening with Jest too. I would be glad we could expose the _document variable. I think it won't introduce any issues. As in, Vue is too exposing a lot of private fields.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants