React 18 & React-Testing-Library performance vs Jest #6098
Replies: 3 comments 1 reply
-
Don't have much time to answer everything here, but for performance issues you can try using |
Beta Was this translation helpful? Give feedback.
-
I moved away from using beforeEach(() => {
// see https://github.com/testing-library/user-event/issues/1115#issuecomment-1565730917
if ('vi' in global) vi.stubGlobal('jest', { advanceTimersByTime: vi.advanceTimersByTime.bind(vi) });
}); This change did not affect my timings, so I also noted a few tests where beforeAll(() => {
// see https://github.com/capricorn86/happy-dom/wiki/IOptionalBrowserSettings
vi.stubGlobal('happyDOM', merge(('happyDOM' in global) ? global.happyDOM : {}, { settings: { disableJavaScriptFileLoading: true, handleDisabledFileLoadingAsSuccess: true } }));
});
afterAll(() => {
vi.unstubAllGlobals();
}); This change also did not affect my timings. |
Beta Was this translation helpful? Give feedback.
-
After reading through a few of the older issues, including #579 I think I have a pretty good idea about what to expect and what tuning is available to me. This article was linked in that issue and has helped: https://dev.to/thejaredwilcurt/improving-vitest-performance-42c6 The following actions had the greatest impact in my case. The tests are now running in 90-100s which is close enough to what we had in
|
Beta Was this translation helpful? Give feedback.
-
I've been following
vitest
for over a year and up till recently I had only used it in a few node projects. I have been really impressed with the performance so decided to adopt it for a bigger React 18 SPA I work on. I was surprised to see the performance vsjest
take quite a hit.We have ~1100 tests and locally with
jest
(CRA + Craco + Babel) they took about 90s on average on my laptop, 120s in CI. After moving tovite
, and then adoptingvitest
I now get 200s locally and 240s in CI.I know that these topics are less than helpful without examples, but I'm unfortunately unable to share this code base. I was really just raising this topic to see if what I'm seeing is out of the norm (and most people are getting the same or better timings vs jest), or if vitest is a little slower in this context right now?
I have tried both
happy-dom
andjsdom
, as well asforks
andthreads
, and get similar results. I haven't spent a great deal of time debugging the tests yet to see if something in particular is taking longer than I would expect. But skimming over their individual timings, they don't seem unusual at first glance, and from what I can see my CPU is pegged at 100% throughout the run.During the migration I did run into two issues that might be impacting things (or indicators of something wrong in some tests)...
the first was
v8
coverage not working for me due to hanging processes, when trying to debug getting would just get empty stack traces. Usually it would surface the following error, so I reverted back toistanbul
for now. Either way the timings above are with coverage disabled and the only reporter set toverbose
(so is unlikely impacting times).the second issue was that
vi.useFakeTimers()
didn't seem to play well with@testing-library/react
. To getvi.advanceTimersByTime()
to work, I had to usevi.useFakeTimers({ shouldAdvanceTime: true })
which didn't feel right, so am wondering if its synthetically delaying stuff. There are some issues here, here and a workaround suggestion here.I plan to spend some time next week debugging further, but was hoping to get an idea from others about what performance differences they are seeing between jest and vitest in their projects, so I can set my expectations.
Beta Was this translation helpful? Give feedback.
All reactions