What do I look for in a Node.js test framework, fastify.io outage and other Adventures in Nodeland
Hi Folks,
Two weeks have passed since the last Adventures in Nodeland edition. I have been swamped catching up with my backlog, and it is not getting shorter. I'm currently at 100+ notifications on GitHub to process: if you have been waiting for me for anything, let me know.
This newsletter explains one of the questions I got asked the most: "What test framework do you recommend," and I've been trying to answer. Then it includes a couple of video links as well as quite a lot of releases and articles.
What do I look for in a Node.js testing framework?
There are two main features that I need when evaluating a unit test framework:
- no required runner
- not intrusive
- support for code coverage
The ability to execute the test without a runner is critical: very often, you stumble on a problem, and you need to use --inspect
, pass some custom NODE_OPTIONS
, or even read the output unfiltered. This feature allows me to test lower-level issues within applications without switching unit test frameworks. The frameworks that support this are: node-tap
, vitest
, tape
, node:test
.
A unit test framework should not alter the globals of the runtime. If those are changed, debugging complex issues makes debugging harder because a bug could result from a bad interaction between your test framework and your codebase. Unfortunately, jest
changes the globals of the JavaScript runtime heavily, making it extremely hard to test specific error paths with it.
Lastly, I do not want to figure out how to set up code coverage for my toolchain, and I would like a framework that works out of the box.
Based on this criteria, my long-term preference is node-tap
, but node --test
is quickly becoming my go-to choice for small and large apps.
Videos
In the Live Stream of the 15th of June, I'm back fixing Platformatic Bugs: - Only add SQLite watch ignores in the config file #1099; - Add support for generating a client from a file #1100.
Last weekend Fastify.io was down - here is a quick explanation of what happened: https://youtu.be/ZjXA-qm772Y.
Releases
- @fastify/reply-from v9.2.0 fix proxying with double slash.
- @fastify/request-context v5.0.0 uses vanilla
AsyncLocalStorage
instead ofasynchronous-local-storage
. - @fastify/swagger-ui v1.9.0 update Swagger UI to v5.0.0.
- undici-tls-dispatcher v0.2.0 drops support for Node.js v16.x.
- @fastify/awilix v3.1.0 adds the integration with
awilix-manager
and support for Node v20. - @fastify/accepts v4.2.0 integrates
@types/accepts
. - @fastify/rate-limit v8.1.0 updates types.
- @fastify/multipart v7.6.1 avoid piping the same file multiple times in case
saveRequestFile
is called twice. - @mercuriujs/gateway v2.0.0 bump
mercurius@13.0.0
and adds support for Node.j v20. - @fastify/reply-from v9.3.0 does not relies on
instanceof
to detect undici instances - multiple versions could be used. - piscina v4.0.0 drop supports for unsupported Node.js versions.
- @matteo.collina/sqlite-pool v0.1.0 a Pool for SQLite connection to interact with a single database in parallel.
- @fastify/swagger v8.6.0 improve types by supporting read-only schema, and removing the
JSONObject
type fortransform
; it also adds support for thedescription
field on OpenAPI and swagger bodies. - @fastify/reply-from v9.4.0
- @fastify/multipart v7.7.0 includes
ajvFilePlugin
into the project. - @fastify/scheduler v4.1.1 supports toad-scheduler v3.
- piscina v4.0.0 drop supports old Node.js versions.
- @fastify/oauth2 v7.1.1 changes
bearer
toBearer
to match spec. - @fastify/http-proxy v9.2.1 fixes websocket proxying on a given path.
Articles
- Wrapping any Fastify application into Platformatic is easy! Check out "How to migrate a Fastify app to Platformatic Service"
- The most asked question I get is "how to migrate an Express application to Fastify". Here is part of the answer; migrate it to Platformatic
- Fundamentals of Fastify: The Best Node.js Framework - thanks Bhadresh for writing this article on Fastify.
- Creator Flywheels – The Operating System for Your Business - "A flywheel builds momentum. A flywheel’s inertia, or kinetic energy, keeps things spinning despite any fluctuations. When your business is driven by content, a flywheel is crucial for combatting lack of motivation and inspiration." - what an interesting read!
- Promise not to promise - Jason Fried of Basecamp describes what not to do when building an online product: promise new features on a timeline.