Your test suite
node:test
node:test suite gets a record of
the lines of your code each case ran. One script replaces the node --test
command, and nothing in your test files changes. Then CI starts only the test
files your change reached, you can read what one test did, and you can ask
which tests cover a line.Try it
You need Node 22.15 or newer. The script runs each file in its own process, as
node --test does.
npm install --save-dev @variance-authority/sense @variance-authority/cli
// 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;
Run node scripts/test.mjs once to write the record, change a source file, and
run again:
$ VARIANCE_AUTHORITY_SINCE=origin/main node scripts/test.mjs
variance-authority: selected 1 of 2
What you get
Leave out the test files a change did not reach
The files the record shows the diff did not reach are not started. A file that failed, or whose process died, is recorded incomplete and runs next time. Run the suite without the variable on your mainline after a merge, so the next diff is read against a fresh record. Run the tests an edit needs walks through the loop.
Read one test's story
Set VARIANCE_AUTHORITY_STORY=1 on the script for one file, then run
variance story. It lists the calls of your code the case made, in order.
Record one shows the steps.
Ask which tests cover a line
variance covering --file src/label.cjs --function label
It names the cases that ran label, each under its describe blocks, such as
label > takes the alpha path.
Covering
lists every way to ask.
Not yet
- Skipping cases inside a kept file: a kept file runs whole.
- Shard placement by recorded time.
- A documented setup for visual review.
- Recording under Bun's
bun test: Bun is not recorded says why and what runs instead.
Go further
- The
node:testreference: what the script records and how it names each case. - Record a runner this package has no seam for, for
suite,rootand every option. - What a skipped test promises: the rule behind each
node:testskip. - Supported frameworks puts
node:testbeside every other runner.