-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fake timers don't work for performance.now()
#4004
Comments
It doesn't do this by default yet, but you can enable it with fake timers config: import { configDefaults } from 'vitest/config'
export default {
test: {
toFake: [...configDefaults.toFake, 'performance']
}
} |
@sheremet-va amazing, thank you so much! It works now with this config in my particular case (100% TypeScript): /* vitest.config.ts */
import {defineConfig, configDefaults} from 'vitest/config';
export default defineConfig({
test: {
fakeTimers: {
toFake: [...(configDefaults.fakeTimers.toFake ?? []), 'performance'],
},
},
}); Reference: satelllte/adsr@aceb6e1 Stdout: (before) performance.now() [1] | 0
(before) performance.now() [2] | 0
(before) performance.now() [3] | 0
(after) performance.now() [1] | 5000
(after) performance.now() [2] | 5000
(after) performance.now() [3] | 5000 |
This one really got me as well. Apparently, while the vitest documentation for Leaves me uneasy knowing you're not passing through defaults, but using your own and not documenting discrepancies appropriately. Like, how can I trust any defaults after this? :( |
It looks like there is a slight difference with jest about what's faked by default:
while Vitest has: vitest/packages/vitest/src/defaults.ts Lines 52 to 60 in 7d18233
(Probably new API like I don't think we can just suddenly align this with jest (also |
Vite and vitest is opinionated. That's a fine choice, but it does require that the opinions are well documented, so clearing this up in the docs would be good, and sufficient. |
Actually, the reason why we define those keys as default is because this was specified as the default in fake-timers README or docs. We never intended to be opinionated. Ideally, we should probably just remove it from defaults. |
Always hard knowing where the flakiness starts and ends in the JS ecosystem, unfortunately.. :( Sorry to direct my frustration at you if indeed the issue started in fake-timers readme and not here. |
Describe the bug
Hi 👋
I'm not sure if this a bug or not, but I noticed that Vitest fake timers don't work with High precision timing Web API, specifically for
performance.now()
.Is it possible to support it?
Reproduction
Code snippet:
satelllte/adsr#46
Stdout example:
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: