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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest version of Happy DOM hangs Vitest #1233

Closed
6 tasks done
capricorn86 opened this issue May 4, 2022 · 9 comments 路 Fixed by #1234
Closed
6 tasks done

Latest version of Happy DOM hangs Vitest #1233

capricorn86 opened this issue May 4, 2022 · 9 comments 路 Fixed by #1234

Comments

@capricorn86
Copy link
Contributor

capricorn86 commented May 4, 2022

Describe the bug

First I just want to say that this is a great library and I have recommended it to a lot of people. It is also really fun that Happy DOM is used as I am the creator of it 馃檪

I just released a new major version of Happy DOM, which I believe is causing Vitest to hang in some scenarios.

In the latest major version of Happy DOM, the Window object is a VM context. This means that global keys like Object, Array, Function etc. in the Window instance are unique to the context and will not be the same as in the global object. The change was done to solve multiple problems reported to Happy DOM.

Now when I looked at the Vitest code I noticed that the keys from the Window instance are copied to the global object. It will then override native properties (like Object, Arrray, Function etc.) with another version unique to the VM context. This will probably cause all kinds of weird behaviors.

I wish I knew that Vitest imported Happy DOM this way. I would have handled the release differently then 馃槄

Happy DOM now exports a class called GlobalWindow, which is meant to be executed within the global context.

To solve the problem either Vitest changes to use GlobalWindow, or Happy DOM changes Window to be the global window and creates a new window class called VMWindow (or similar).

Bug in Happy DOM:
capricorn86/happy-dom#462

Reproduction

Reproduce global reference issues

This will fail:

import { describe, expect, it } from 'vitest';

describe('suite name', () => {
    it('foo', () => {
        expect([].constructor).toBe(Array);
    });
});

Reproduce Vitest hanging
In the issue in Happy DOM several users described scenarios where just a few tests had to be run for it to happen, but I was only able to reproduce it consistently in:
https://github.com/ueberbit/lib

To reproduce:

  1. git clone https://github.com/ueberbit/lib.git
  2. cd ./lib
  3. npm i
  4. npm test

System Info

OS: Ubuntu 21.10
Vitest version: v0.10.2
Happy DOM version: v3.1.0

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

sheremet-va commented May 4, 2022

Thank you very much for your reference! We saw that we had a problem with new version of happy-dom, but didn鈥檛 have time to dig in. This will surely help us fix the issues 馃槃

I think we can just check for GlobalWindow, and use it. If it doesn鈥檛 exist, fallback to Window. This should work with both versions, I guess?

@capricorn86
Copy link
Contributor Author

capricorn86 commented May 4, 2022

@sheremet-va yes that should solve the issue for both versions 馃檪 馃憤

@sheremet-va
Copy link
Member

@capricorn86 unfortunately simple GlobalWindow || Window didn't help: #1234

Maybe you have other ideas why this might happen?

@sheremet-va sheremet-va added the bug label May 5, 2022
@capricorn86
Copy link
Contributor Author

@sheremet-va I have now debugged and apparently the import of a package called "sync-request" caused the issue. Not sure what is happening, but I will make a fix for it as soon as possible in Happy DOM.

I still suggest changing to use GlobalWindow instead of Window as other problems could emerge otherwise.

@capricorn86
Copy link
Contributor Author

There is now a fix available in the latest version of Happy DOM (v3.1.1) 馃檪

@sheremet-va
Copy link
Member

sheremet-va commented May 5, 2022

It seems, it still fails on Node 16 on Windows 馃

https://github.com/vitest-dev/vitest/runs/6309436372?check_suite_focus=true


Edit: Hm, on the third rerun it passed 馃

@capricorn86
Copy link
Contributor Author

Weird 馃

I only tested in the project mentioned above where it hanged and there the fix solved the problem, but I can try to debug with the test you ran as well.

@sheremet-va
Copy link
Member

Weird 馃

I only tested in the project mentioned above where it hanged and there the fix solved the problem, but I can try to debug with the test you ran as well.

Maybe it was just a fluke. We released the fix in 0.10.4, let's see how it will play out 馃槃

@capricorn86
Copy link
Contributor Author

Yes, hopefully! 馃槄 It works now for the consumers that reported the problem in Happy DOM at least.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 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.

2 participants