Your test suite
Playwright
playwright.config.ts
once and build the application with probes in it. Then CI runs only the spec
files your change reached, you can read what one test's pages 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/playwright-test @variance-authority/sense @variance-authority/cli
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
import { withTestSelection } from '@variance-authority/playwright-test';
export default defineConfig(withTestSelection(
{ projects: [{ name: 'chromium', use: devices['Desktop Chrome'] }] },
{ preconditions: ['tsconfig.json'] },
));
// tests/fixtures.ts: your specs import test from here
import { test as base, expect } from '@playwright/test';
import { varianceFixtures } from '@variance-authority/playwright-test';
export const test = base.extend(varianceFixtures);
export { expect };
Your code runs in the page, so the build the tests drive must place probes in
it: add testSelectionProbes() from @variance-authority/sense/journal to its
Vite plugins, or testSelectionRule() to an Rspack or webpack build. Run
npx playwright test once to write the record, change a source file, and run
again:
$ VARIANCE_AUTHORITY_SINCE= npx playwright test
variance-authority: selected 4 of 31
What you get
Leave out the spec files a change did not reach
The wrap adds the spec files your change did not reach to testIgnore, so
Playwright never loads them. A spec whose test failed, or whose page went to
another origin, is recorded incomplete and runs next time. Leave out the specs
a change did not
reach
has the details.
Place shards by recorded time
Under npx playwright test --shard 3/4, the wrap's reporter places whole spec
files by the time each took on the last recorded run, in place of Playwright's
split by test. It needs Playwright 1.62 or newer. Split a test suite across CI
jobs gets those times to CI.
Read one test's story
Name one spec and one test to npx playwright test -g with
VARIANCE_AUTHORITY_STORY=1 set, then run variance story.
The story lists the calls of your code the test's pages made, in order. Each
statement of the spec opens what the page did next, and a navigation marks
where the next document starts. 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 Playwright tests
whose pages ran line 40.
Covering
lists every way to ask.
Visual review
Your test already gets the page into the state you want to review, so visual
review is one call in the test body, on the locator you pass. A changed region
is reported with the component that drew it, and toHaveScreenshot() stays
where you use it. Add one observation to a Playwright test
sets it up, with no wrap needed.
Not yet
- Skipping tests inside a kept spec file: Playwright runs it whole.
- Selection in watch mode, UI mode or
--list. - Shard placement below Playwright 1.62: the wrap refuses the sharded run.
Go further
- Record what a driven page executed, and a build Rspack or webpack bundles.
- Record what each spec executed: every option of the wrap.
- Recording what a service executed, for code a server runs.
- Choose where pixels are made, deferred or in place.
- Supported frameworks puts Playwright beside every other runner.