-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Describe the bug
When you
- enabled coverage
- mock
Math.randomand not restoring the original function after test
vitest hangs up.
If you run the same code with jest, it finishes.
const t = typeof vi !== 'undefined' ? vi : jest
test('Math.random mock', () => {
// const original = Math.random
const mocked = t.fn(() => 0.1);
Math.random = mocked
// Math.random = original
});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
- Download zip and extract
npm cinpm run jestruns successfullynpm run vitestnever ends
(stackblitz did not work)
System Info
System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 12.61 GB / 31.93 GB
Binaries:
Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
npm: 8.1.3 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 98.0.4758.102
Edge: Spartan (44.19041.1266.0), Chromium (99.0.1150.30)
Internet Explorer: 11.0.19041.1202
npmPackages:
vitest: ^0.5.9 => 0.5.9Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels