DEV Community

Bosco Domingo
Bosco Domingo

Posted on

Node Test Runner vs Bun Test Runner (with TypeScript and ESM)

I've recently gotten the chance to play with both of these while looking for a long-term testing framework at my job.
I also considered Node-TAP, Vitest, Jest and Mocha, but none truly convinced me as much as these two for a multitude of reasons (annoying config, lack of ESM support, speed, etc), so I'll focus on them.

Node Test Runner

The good

Built-in. That's it, so simple, so nice. Plus it works with ESM too!

Use

It has everything you'd expect (describe/it, mock, test, beforeEach, etc...) and uses assert instead of the usual expect.

assert.equal(id.value, expectedId);
Enter fullscreen mode Exit fullscreen mode

The bad

No TS support out-of-the-box. So much so, that you need to do a hacky workaround in your package.json scripts:

"test" "glob -c \"tsx --test --test-reporter spec \" \"./test/**/*.test.ts\""
Enter fullscreen mode Exit fullscreen mode

You need both a loader (tsx or similar) and a way to tell it where your tests are (in this case, glob).

This snippet comes from the guide I made on setting up Node Test Runner for TypeScript, so check it out if you want more info!

Bun Test Runner

The good

It's fast. Like twice as fast as Node's runner, which was already faster than Jest and Vitest. It also is as easy to set up as Node's Test Runner, and includes TS support as well!

Use

It has a decent compatibility with both Jest and Vitest's APIs (you can track progress here so you can use it as almost a drop-in replacement for either.
Just as Node's, it has describe/it, mock, test and others, but with the expect syntax (which I find more readable). For example:

expect(id.value).toEqual(expectedId);
Enter fullscreen mode Exit fullscreen mode

The bad

Iffy debugging support. It requires the VS Code extension if you use VS Code, and I'm not sure how well other IDEs are supported. It also requires installing Bun as a dependency in package.json if you still use npm/pnpm/yarn to pin the right version.

Verdict

If you already use Bun, or don't mind having to use additional tools for debugging, then Bun is definitely the choice to make. It's easier to use and faster, and has about the same functionality if not more than Node's.

If on the other hand you care about "native" experience, want the best CI installation times, or just want to use all-Node, then the good news is that Node's Test Runner is not far behind, and you won't feel like you're being left out for not using the most blazingly fast™ tool.

In any case, either one should be a good choice as they are seeing active development (Node just released version 22, and Bun announced v1.1 three weeks ago as of the time of writing) and aim to be easy-to-use, fast tools.


Hope this article was of use in helping you decide which one to go for, and don't forget to check all my other stuff for more posts like this one!

Top comments (0)