pontoon icon indicating copy to clipboard operation
pontoon copied to clipboard

Replace Jest with Vitest as test runner

Open eemeli opened this issue 3 months ago • 7 comments

While working on #3766 I was struck again by the clunkiness of Jest, and the difficulties of getting it to work with ES modules.

We would probably be better off switching instead to Vitest as our frontend test runner, esp. as our use of Jest isn't very complex.

I'm marking this as a "good first issue", given that this transition ought to be relatively straightforward.

eemeli avatar Sep 04 '25 15:09 eemeli

@eemeli Can i take up this issue ? If yes , then assign me

Raj-G07 avatar Sep 05 '25 13:09 Raj-G07

@eemeli and @mathjazz Day 1 : Change a lot of test to vitest , but some test which contain sinon and enzyme usecases failed as Vitest is not suitable with sinon and enzyme, so can i move to RTL + Vitest .

Raj-G07 avatar Sep 06 '25 14:09 Raj-G07

hey @eemeli, @mathjazz , i was working on this issue and found that vitest has compatibility issues with sinon, mainly the places where we directly mock imported module and use sinon to stub it, i guess this might be because the esm modules imports are readonly (transformed by Default by vite), so sinon modification are not applied. i want to confirm that should we remove sinon entirely as their might future compatibility issues in future too, or just patch broken pieces with vitest equivalent.

i will be creating Mr for the changes i have made in 1-2 days, following 3 MR plan you mentioned in #3769 And, can you please assign this task to me?

nishitmistry avatar Nov 23 '25 16:11 nishitmistry

Feel free to replace our Sinon usage with Vitest equivalents as necessary. As far as possible, changes here should be small steps, so it might turn out to be valid to e.g. only replace some Sinon mocking initially, and follow that up with a separate cleanup PR.

eemeli avatar Nov 24 '25 08:11 eemeli

Ohk, thank you

nishitmistry avatar Nov 24 '25 11:11 nishitmistry

Hey @eemeli, i was porting the sinon stub which were failing and saw that some of them fails because they aren't in a body of a function component. we either Wrap the hook in a small test component, Mount that component with Enzyme and Assert on what it renders or passes out Or add React testing Library which would in theory make this less tedious. Would love to here your thoughts

nishitmistry avatar Dec 06 '25 14:12 nishitmistry

Moving tests from Enzyme to testing-library would be the preferred way forward.

eemeli avatar Dec 08 '25 15:12 eemeli