Node.js › Advanced Node.js
How does Node.js's built-in test runner (node:test) compare to third-party frameworks like Jest or Mocha?
AdvancedAnswer
Node's built-in test runner (stable since Node 20, available via node:test) provides test suites, hooks (before/after), mocking, code coverage, and a TAP-compatible reporter without any external dependency -- reducing install size and avoiding version-compatibility churn. It lacks some of Jest's more advanced features out of the box (like built-in snapshot testing or extensive matcher libraries), but for many projects it's now sufficient on its own, and can be paired with assert or a lightweight assertion library.
const { test } = require('node:test');
const assert = require('node:assert');
test('adds two numbers', () => {
assert.strictEqual(1 + 1, 2);
});
// Run with: node --test
// Or with coverage: node --test --experimental-test-coverageReal-world example A small internal CLI tool drops its Jest dependency entirely in favor of node:test, since the project has minimal testing needs and removing Jest cuts the node_modules install size significantly and eliminates a whole category of dependency-version conflicts.