Sean Massa's Labs

Comparing: JavaScript Test Runners

2024-01-31 #software-engineering

Every so often, I like to survey the JavaScript test runner space to see what's out there. This time, I was pushed to do so by continuing to hit bugs and limitations of Jest.

I worked with my team at Vercel to flesh out this comparison.

Spoiler: vitest wins.

Context

Recent Jest issues I've Iencountered:

Test runner libraries under consideration:

Features

Requirements:

Nice to haves:

Comparison

Feature Matrix:

Feature jest vitest mocha node-tap node:test
maturity veteran mature veteran veteran stable in 20.0.0
parallelization ~ Y Y Y Y
shard Y Y N N Y
JS modules / ESM ~ Y Y Y Y
TypeScript Y Y Y Y Y*
hooks failure N Y Y N Y
hooks order N N* N Y N
no globals required N Y Y Y Y
no globals overridden N Y Y Y Y
----- Nice to Have -----
low startup time ~341 ms ~941 ms ~290 ms ~794 ms ~193 ms
snapshots Y Y N Y N
mock imports Y Y N Y N
non-trivial assertions Y Y N Y Y
bail / fail fast N Y N Y Y*
watch mode Y Y Y Y Y
line coverage Y Y N Y ~

Key:

Decision

vitest!

The only tool that meets almost every requirement and nice-to-have is vitest. That's my new default decision.

If you notice anything wrong in this chart, please let me know!

Comparing: JavaScript Test Runners | Sean Massa's Labs