-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Mocking Math.random
and not restoring makes vitest hang up when coverage is enabled
#903
Comments
We cannot guarantee that no one uses global APIs when running tests. Just restore it to original after each test: afterEach(() => {
Math.random = originalRandom
}) |
I thought the environment which is running tests is isolated from the environment which is collecting coverage. But actually the test did not fail with timeout. Is this intended? If it is intended, I am ok with closing this issue. |
They are run in the same env (not isolated, like jest does with Currently we are not planning on changing the way tests are run, because |
Thank you for the explanation! I understand. |
Describe the bug
When you
Math.random
and not restoring the original function after testvitest hangs up.
If you run the same code with jest, it finishes.
When you restore
Math.random
it will work. (uncomment line 4 & 7)I think it does not need to end the test successfully, but at least fail with timeout.
Because it is hard to find which test is hanging up.
Reproduction
https://gist.github.com/sapphi-red/d3454a362c3b66e3654918516c808d7e
npm ci
npm run jest
runs successfullynpm run vitest
never ends(stackblitz did not work)
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: