VARIANCE AUTHORITY
BrowseRstest

Your test suite

Rstest

What Variance Authority does for your Rstest suite starts from one record: the lines of your code each Rstest test ran. You wrap 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=case fails the run.
  • Shard placement by recorded time: Rstest's --shard divides by count.
  • Selection in watch mode.

Go further