CheckOps
Node.js Test Runner (node:test)
The Node.js test runner is the built-in `node:test` module, stable since Node.js 20, providing describe/it tests, mocking, snapshots, coverage and reporters with no extra dependencies.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
Node.js ships its own test runner in the node:test module. It was added in Node.js 18 and the documentation marks it as Stability 2 – Stable. Tests are written with test() or describe()/it(), assertions usually come from node:assert, and node --test discovers and runs test files automatically.
The runner has grown into a capable framework. The documentation covers subtests, only/skip/todo, hooks, watch mode (--watch), function and timer mocking (mock.fn, mock.method, mock.timers), snapshot testing, code coverage (--experimental-test-coverage) and built-in reporters including spec, TAP, dot, JUnit and lcov. Because it is part of Node.js, it needs no installation and is MIT-licensed along with Node.js itself.
For teams migrating, the main adjustment is assertions: node:assert/strict replaces expect, and the docs show how to plug in custom reporters or write results to files with --test-reporter-destination, so CI can produce both console output and a JUnit file in the same run.
Features
- Zero dependencies: Built into Node.js; run with
node --test. - Mocking: Function, method and timer mocks via the
mockAPI. - Coverage and reporters: Experimental coverage plus spec, TAP, dot, JUnit and lcov reporters.
- Watch mode:
--watchre-runs tests on change.
Pros
- Free: Included with Node.js at no cost.
- Stable API: Marked Stability 2 – Stable in the Node.js docs.
Cons
- Fewer conveniences: No built-in module mocking as rich as Jest or Vitest, and coverage is still flagged experimental.
- Version-dependent features: Available features depend on your Node.js version; check the docs for your release.
Usage and Links (Example)
// test/math.test.js
import { test, describe, mock } from "node:test";
import assert from "node:assert/strict";
import { add } from "../src/math.js";
describe("add", () => {
test("adds numbers", () => {
assert.equal(add(2, 3), 5);
});
test("calls logger", () => {
const log = mock.fn();
add(1, 1, log);
assert.equal(log.mock.callCount(), 1);
});
});
node --test --test-reporter=spec
node --test --experimental-test-coverage
Resources:
Pricing
Free and open source as part of Node.js (MIT licence).
Recommended for?
- Node.js libraries and services wanting fewer dev dependencies.
- Teams standardising on platform tooling for long-term stability.
Conclusion
The built-in Node.js test runner is now a credible default for many projects: no install, stable APIs, mocking, snapshots and reporters out of the box.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with Node.js Test Runner (node:test) side by side.
JJestJest is a free, open-source JavaScript test runner with zero-config defaults, mocks, and snapshot testing.Compare with Node.js Test Runner (node:test)
VVitestVitest is a free, open-source unit test runner that reuses a Vite project's config, transforms, and plugins.Compare with Node.js Test Runner (node:test)
MMochaMocha is a long-running, MIT-licensed JavaScript test framework for Node.js and browsers, with BDD and TDD interfaces, async support, hooks, parallel mode and a large reporter ecosystem.Compare with Node.js Test Runner (node:test)
AAVAAVA is an MIT-licensed Node.js test runner that runs test files concurrently in separate worker processes, with a minimal API, clean output, built-in assertions and snapshot support.Compare with Node.js Test Runner (node:test)
Nnode-tapnode-tap (the `tap` package from tapjs) is a full-featured Node.js test framework built on the Test Anything Protocol, with TypeScript support, built-in coverage, snapshots, mocking and a plugin system.Compare with Node.js Test Runner (node:test)
BBun Test Runnerbun test is Bun's fast, built-in, Jest-compatible test runner with TypeScript and JSX support, lifecycle hooks, mocks, snapshots, DOM testing, coverage, watch mode and GitHub Actions annotations.Compare with Node.js Test Runner (node:test)