Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

node –test: The Test Runner You Already Have Installed

Node.js ships with a test runner. Learn how node --test finds files, isolates them in child processes, and what watch, coverage and mocking offer.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes, Node.js has a built-in test runner. Run node --test in a project and Node finds matching test files, runs them, and reports results. You define tests with the node:test module. You don’t install a separate runner package. This guide covers the first test, how files are discovered, process isolation, and the extras (watch mode, coverage, mocking). It also gives the stability label for each extra, because those labels vary by release.

Write and run your first test

The Node.js documentation describes the runner this way: “The Node.js test runner can be invoked from the command line by passing the --test flag.” The tests themselves come from the node:test module, and assertions come from node:assert. Both ship with Node.

Create a file named math.test.js:

import test from 'node:test';
import assert from 'node:assert';

test('adds two numbers', () => {
  assert.strictEqual(1 + 2, 3);
});

Then run:

node --test

Node discovers the file, runs it, and prints a result for each test. A test passes if its function returns without throwing. A failed assertion throws, so the test fails. The example uses ES module import syntax. In a CommonJS project, use require('node:test') and require('node:assert') instead.

How Node finds your test files

Not every .js file counts as a test. Without arguments, the runner looks for files matching documented naming patterns. The current documentation lists these:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • example.test.js
  • example-test.js
  • example_test.js
  • test-example.js
  • test.js
  • files under a test/ directory

The documentation also covers TypeScript extensions when type stripping is in effect. Passing --no-strip-types changes that behavior.

Choosing files yourself

To override the defaults, pass explicit glob patterns. Quote them so your shell doesn’t expand them before Node sees them:

node --test "src/**/*.spec.js"

This is the fix when your naming convention doesn’t match the defaults, or when you want to run one slice of the suite.

Process isolation: why files don’t share state

By default, each matching file runs in its own child process. Files therefore don’t normally share one JavaScript global context. A global variable or a patched built-in in one file won’t leak into another.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Concurrency: the --test-concurrency flag controls how many child processes run at once.
  • Turning isolation off: if you disable process isolation, files share a context. Global state can then cause cross-file interference, so only do it if your tests are written with that in mind.

Useful features beyond the basics

Feature How to use it Stability label in the v26.8.2 docs
Watch mode node --test --watch Experimental
Coverage node --test --experimental-test-coverage Experimental
Mocking Provided by the node:test API Not stated in the material reviewed
Global setup/teardown Documented as added in v24.0.0 Early development

Watch mode

The documentation says: “In watch mode, the test runner will watch for changes to test files and their dependencies.” Edit a file and the affected tests rerun, which suits a tight edit-and-test loop.

Coverage

Add --experimental-test-coverage to get a coverage report with your test results. The flag name itself carries the experimental label.

Mocking

The node:test module includes mocking support, so you can replace functions or methods during a test without a separate mocking library. See the Test runner page for your Node version for the exact API.

Global setup and teardown

This appears in the v26.8.2 documentation as added in v24.0.0 and is labeled early development. Don’t rely on it in older releases, and expect it to change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check your Node version

Flags, defaults and stability labels differ between releases. The details above come from the Node.js v26.8.2 Test runner documentation. Run node --version, then read the Test runner page for that version at nodejs.org before depending on an experimental flag or a feature added recently. This page doesn’t compare the built-in runner with third-party frameworks. Whether it replaces one in your project depends on the integrations and features you need.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.