-
-
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
[Vitest 3] performance.now()
Issue
#7198
Comments
I think what affected you is probably #6288. I'm not sure if this is fake-timer issue. Probably, they mutate only
Can you provide a link to the code? Also having more realistic test cases would be nice to understand the significance of the issue. |
If someone did Note that I'll close this for now, but I'm curious what's the situation with |
Thanks for having a look @hi-ogawa As for It was a little tricky to figure out exactly what was happening originally, but I grant this is probably a fairly uncommon use-case 😁 In any case, I'm sure I can work around it easily, including the suggestions you mentioned above. Thanks again 👍 |
Describe the bug
It's a little tricky to explain, but using the latest beta version (3.0.0-beta.4), I am getting some new test failures when the code under test is using
performance.mark()
, which errors because it internally tries to useperformance.now()
as a default, and that is returning a negative timestamp.It seems the timestamp being generated by
performance.now()
is now being affected by the faked "now" timer, and if that timer is in the past, the timestamp is negative, andperformance.mark()
breaks.Note that this only seems to be the case when
window.performance
is assigned to a variable prior to the timer being mocked.I assume this is perhaps somewhat related to #7097.
It's probably best demonstrated with the reproduction below.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-a9ymmqty?file=vite.config.ts,package.json,test%2Fbasic.test.ts,tsconfig.json&initialPath=__vitest__/
You can see the test contains two logs. Even though they essentially call the "same"
now
function, the former (whereperf
is assigned before the timer is faked) returns a negative timestamp, and latter returns a (presumably mocked) 0.If you revert to version
2.1.6
of Vitest, you'll see that both calls now return the same (positive) value.Note that, in my case, the code using
performance.mark
is internally withinvue-i18n
so I can't easily change where the calls are made. Apologies if the underlying problem is more accurately attributed to a different lib (e.g., sinon, vue-i18n, etc).System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: