# `node:test` reference

This page is the reference for recording a `node:test` suite with
`runNodeTest`: what the script records and how it names each case, why Bun's
`bun test` is not recorded, and when a file it leaves out could still have
failed. [`node:test`](https://variance-authority.dev/docs/node-test/index.md) sets the suite up in a few lines.

## Record which tests ran each line

Install the package, which needs Node 22.15 or newer:

```bash
npm install --save-dev @variance-authority/sense @variance-authority/cli
```

Write the script that runs the suite:

```js
// scripts/test.mjs
import { runNodeTest } from '@variance-authority/sense/node-test';

const { passed } = await runNodeTest({
  files: ['test/alpha.test.mjs', 'test/beta.test.cjs'],
});
process.exitCode = passed ? 0 : 1;
```

```bash
node scripts/test.mjs
```

It runs each file in its own process, as `node --test` does with its default
isolation, and writes the suite's [execution record](https://variance-authority.dev/docs/execution-record/index.md).
`node:test` has no config file for a wrap to go in, so this script is where the
record is turned on. Test files can be ES modules or CommonJS.

A case is recorded under the `describe` blocks around it and its own name, such
as `label > takes the alpha path`. A hook, and a subtest started inside a case,
runs as it does without the record and has no row of its own. A file that
fails, or whose process dies, is recorded as incomplete, and an incomplete file
is run by every later selection.

`runNodeTest` takes the same options as the [other runners'
recording](https://variance-authority.dev/reference/packages/sense/index.md#record-a-runner-this-package-has-no-seam-for),
such as `suite` and `root`.

### Bun is not recorded

`bun test` runs `node:test`-style files, but the record cannot attach to it. The
recording loads each test file through `module.registerHooks`, which Bun does
not have, so `runNodeTest` stops under Bun with
`Export named 'registerHooks' not found in module 'node:module'`.

Until a Bun seam exists, record the suite under Node with the script above and
keep `bun test` as the runner you ship with. A file that imports only
`node:test` and `node:assert` runs under both.

## Run only the tests a change reached

The record answers for the commit it was made at. Run the suite without
`VARIANCE_AUTHORITY_SINCE` on your mainline after a merge, so the next diff is
read against a record of the code it starts from. [Run the tests an edit
needs](https://variance-authority.dev/docs/test-an-edit/index.md) walks through the loop.

`VARIANCE_AUTHORITY_GRAIN=case` is refused here rather than read as honoured:
`node:test` runs a kept file whole.

### When a left-out test could still have failed

No case is known where `node:test` leaves out a file that would have failed:
each file runs in its own process, and a kept file runs whole. A file the record
has no row for, or whose row is incomplete, runs. [What a skipped test
promises](https://variance-authority.dev/docs/selection-safety/index.md) states the rule for every runner.
