DEV Community

Cover image for Vitest is fast, jest is faster *
Mykolas Mankevicius
Mykolas Mankevicius

Posted on


Vitest is fast, jest is faster *

  • for the more real world cases is claiming to be blazing fast, and that maybe the case for some very unity tests with no dependencies.

But if you're writing real world more feature/integration "unit" tests you're better of sticking with what you have already.

I won't go into much detail, but be aware of the issues before deciding to migrate to vitest

Github issues discussing the problems:

I've migrated a large codebase not aware of these issues and now have to wait 10/15 minutes on ci pipeline instead of the 3/4 minutes i used to with jest.

Just be aware of these things before going down the same road i've done.

Latest comments (5)

thenotary profile image

I think this article is still up-to-date. I just came to a project that used vitest instead of CRA to see what it was like to create a react app in a different way. I've just added 3 unit tests that test the <Home /> page produces "Sign in" text somewhere and a few other assertions, but it takes 8 seconds for the test to run. That's a really long time for my computer: Duration 8.60s (transform 626ms, setup 25ms, collect 6.65s, tests 517ms). I'm trying to run tests using the ordinary way, but the configs are all screwed up so we might end up starting over with CRA + typescript if we can't narrow down the problem.

capaj profile image
Jiri Spac • Edited

This article is wrong. If you are working on a modern codebase with TS and es modules, it is fastest test runner ATM, see this comment:

Slowdowns only occur for flow and maybe less files.
For the second problem with coverage, it has been fixed in vitest.

@neophen can you add benchmarks to provide some proof to this "article" of yours?

neophen profile image
Mykolas Mankevicius

So I'm still getting the issues of slow tests, I don't care much about the "a modern codebase with TS and es modules"

A lot of people are still working on old codebases and migrating to vitest hoping to get speed benefits will get burnt. So will not redact my statement so far.

neophen profile image
Mykolas Mankevicius

And actually github issue

If you scroll down you still see people have a lot of issues of vitest being 3x slower than jest.

neophen profile image
Mykolas Mankevicius

It might be wrong by now. I’ll update the article when I have some spare time :)

11 Tips That Make You a Better Typescript Programmer


1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields


Read the whole post now!