Your test suite
node:test reference
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 sets the suite up in a few lines.Record which tests ran each line
Install the package, which needs Node 22.15 or newer:
npm install --save-dev @variance-authority/sense @variance-authority/cli
Write the script that runs the suite:
// 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;
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.
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,
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 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 states the rule for every runner.