Your test suite
Rstest
rstest.config.ts once. Then CI runs only the test files your change reached,
you can read what one test did and ask which tests cover a line, and visual
review runs on your machine and in CI with no hosted service.Try it
npm install --save-dev @variance-authority/sense @variance-authority/cli
// rstest.config.ts
import { defineConfig } from '@rstest/core';
import { withTestSelection } from '@variance-authority/sense/rstest';
export default defineConfig(withTestSelection(
{ globals: true, setupFiles: ['./test/setup.ts'] },
{ preconditions: ['rstest.config.ts'] },
));
Rstest does not say which config file it loaded, so the second argument names
it: a change there runs every test. Run npx rstest run once to write the
record, change a source file, and run again:
$ VARIANCE_AUTHORITY_SINCE= npx rstest run
variance-authority: selected 12 of 340
Keep isolate: true, the Rstest default, so the record sees every module each
test file used.
What you get
Leave out the test files a change did not reach
The wrap adds the files your change did not reach to the project's exclude
before Rstest plans its run, so they never start, and your setup files,
reporters and classic coverage setup stay as they are. Under projects, wrap
each project and the root, and each project prints its own line.
Cut an Rstest run down to a diff
lists every option of the wrap.
Read one test's story
Set VARIANCE_AUTHORITY_STORY=1 on npx rstest run for one test, then run
variance story.
The story lists the calls of your code the test made, in order, with the branch
each one took. In browser mode, each statement of the test opens what the page
did next. Test stories shows how to read one and compare two.
Ask which tests cover a line
variance covering --file src/cart.ts --line 40 names the Rstest tests that
ran line 40. Covering
lists every way to ask.
Visual review
In jsdom or node, a test writes a capture of what it mounted, and a later
variance run paints it in Chromium. Under @rstest/playwright, the test
observes the page it already drives, and -u approves a change. Add visual
review to an Rstest suite sets up both and says which to
choose. Neither needs the wrap.
Not yet
- Skipping cases inside a kept file: Rstest runs it whole, and
VARIANCE_AUTHORITY_GRAIN=casefails the run. - Shard placement by recorded time: Rstest's
--sharddivides by count. - Selection in watch mode.
Go further
- Run the tests an edit needs, with
VARIANCE_AUTHORITY_AT_DISTANCE=0-1for each edit. - A record needs a module graph per test file, for an Rstest run with
isolate: false. - What a skipped test promises: the rule behind each Rstest skip.
- Supported frameworks puts Rstest beside every other runner.