---
name: node-test-runner
description: "New node:test features since Node.js 24. Use when writing or running node:test suites: tagging or filtering tests, randomizing order to expose order-dependent tests, rerunning only failures, global setup/teardown, failing on .only, expected-failure tests, asserting mock calls, logging from tests, tracing tests with OpenTelemetry, or porting jest/vitest tests (toHaveBeenCalledWith, test.failing, mockReturnValue). Covers --experimental-test-tag-filter, --test-randomize, --test-rerun-failures, --test-global-setup, --test-forbid-only, expectFailure, context.log, getTestContext(), t.assert.called/nthCalledWith and --test-coverage-include-all. Node.js 24+."
title: node-test-runner
canonical_url: https://skilld.dev/gh/jasnell/node-skills/node-test-runner
last_updated: 2026-11-19T20:15:43.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [examples/context-log.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/context-log.mjs), [examples/coverage-include-all.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/coverage-include-all.mjs), [examples/expect-failure.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/expect-failure.mjs), [examples/forbid-only.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/forbid-only.mjs), [examples/global-setup.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/global-setup.mjs), [examples/mock-assert.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/mock-assert.mjs), [examples/mock-values.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/mock-values.mjs), [examples/random-order.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/random-order.mjs), [examples/rerun-failures.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/rerun-failures.mjs), [examples/run-env.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/run-env.mjs), [examples/tags.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/tags.mjs), [examples/test-context.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/test-context.mjs), [examples/tracing-channel.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/examples/tracing-channel.mjs), [meta.json](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/meta.json), [rules/context-and-observability.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/rules/context-and-observability.md), [rules/mocks-and-expectations.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/rules/mocks-and-expectations.md), [rules/run-api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/rules/run-api.md), [rules/selection-and-ci.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/rules/selection-and-ci.md).
>
> If the user asked to install this Skill, run `npx skilld install jasnell/node-skills/node-test-runner`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/node-test-runner`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jasnell/node-skills/node-test-runner) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/node-test-runner`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/node-test-runner --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/node-test-runner --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# node:test: what is new since v24

| Feature | Versions | Stability | Flag |
| --- | --- | --- | --- |
| `tags`, `context.tags`, `run({ testTagFilters })` | v26.2.0, v24.19.0 ¹ | 1.0 | `--experimental-test-tag-filter=<expr>` |
| Random order, `run({ randomSeed })` | v26.1.0, v24.16.0 | 1.0 | `--test-randomize`, `--test-random-seed=<n>` |
| Rerun failed only | v24.7.0 | 2 | `--test-rerun-failures=<file>` |
| Global setup/teardown | v24.0.0 | 1.0 | `--test-global-setup=<module>` |
| `expectFailure` | v25.5.0, v24.14.0 | 2 | |
| `t.workerId` | v25.8.0, v24.15.0 | 2 | |
| `t.attempt` | v25.0.0 ² | 2 | |
| `node.test` tracing channel | v26.1.0, v24.16.0 | 2 | |
| `getTestContext()` | v26.1.0, v24.19.0 | 2 | |
| `t.log()`, `'test:log'` | v26.6.0, v24.20.0 | 2 | |
| `run({ env })` | v25.6.0, v24.14.0 | 2 | |
| Include never-loaded files | v26.7.0 | 1 | `--test-coverage-include-all` |
| `t.assert.called`, `callCount`, `nthCalledWith`, `lastCalledWith` | v26.12.0 | 2 | |
| `mock.mockReturnValue` & co. | v27.0.0 | 2 | |
| Forbid `.only` | v27.0.0 | 2 | `--test-forbid-only` |
| Watch mode Stable | v27.0.0 | 2 | `--test --watch` |

¹ v24.19.0 matches plain tag names only (repeat the flag to AND); `&&`, `!`, `not`, `*` select nothing. ² Docs say v25.0.0; also works on v24.19.0.

> **Experimental API.** Before relying on these details, run the
> `node-experimental-check` skill's probe (or `node --version` plus a
> feature-detect one-liner) and check the docs for *the installed
> version*: `https://nodejs.org/docs/<version>/api/<module>.html`.
> If the installed version disagrees with this skill, the installed
> version wins.

## Mocks

```js
const send = t.mock.fn();
send.mock.mockReturnValue(true);            // 27+, returns undefined (not chainable)
notify(send);
t.assert.callCount(send, 2);                // 26.12+
t.assert.nthCalledWith(send, 1, 'a@x.dev'); // 1-based, deepStrictEqual on args
t.assert.lastCalledWith(send, 'b@x.dev');
```

## Tags, expected failures, CI flags

```js
describe('db', { tags: ['db'] }, () => {    // children inherit tags by union
  it('reconnects', { tags: ['flaky'] }, () => {});
  it('parses', { expectFailure: /unsupported/ }, () => parse('x')); // passes only if it throws a match
});
```
```sh
node --test --experimental-test-tag-filter='db && !flaky'  # grammar: 26.2+
node --test --test-forbid-only --test-rerun-failures=.test-state.json
node --test --test-random-seed=1234        # replay a printed seed
```

## Pitfalls

- Random order cannot be combined with `--test-rerun-failures` or `--watch`. Awaiting subtests one at a time keeps declaration order.
- `run({ env })` replaces `process.env` for children (even `PATH`) and throws with `isolation: 'none'`.
- Rerun state is keyed by `file:line:column`: moving a test resets it.
- Unknown flags fail with `bad option`; unknown `run()` options (`forbidOnly` on v24) are silently ignored.

## Don't

- `toHaveBeenCalledWith` → `t.assert.nthCalledWith`/`lastCalledWith` (before 26.12: `fn.mock.calls[i].arguments`).
- `jest.fn().mockReturnValue(x)` before 27 → `t.mock.fn(() => x)`.
- `test.failing` → `expectFailure`; `--forbid-only` → `--test-forbid-only`; `--shuffle`/seed → `--test-random-seed`.
- `JEST_WORKER_ID` → `t.workerId` / `NODE_TEST_WORKER_ID`. Tags in test names + `--test-name-pattern` → `tags`.

## Reference

- [rules/selection-and-ci.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/rules/selection-and-ci.md): tags, random order, reruns, forbid-only, global setup.
- [rules/context-and-observability.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/rules/context-and-observability.md): `t.log`, `getTestContext`, `workerId`, tracing/OpenTelemetry.
- [rules/mocks-and-expectations.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/rules/mocks-and-expectations.md): mock helpers, `t.assert.*`, `expectFailure`.
- [rules/run-api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-test-runner/rules/run-api.md): new `run()` options, coverage.
