Visual regression tests are split into two parts:
- The rendered UI (short: fixture)
- Instrumentation of that UI
The composition of all tests happens in ./index.js
.
The rendered UI is either:
-
located inside a separate file in
./fixtures
and written as a React component.Here is an example with the
Menu
component. -
a demo from
docs/data
By default all demos are included. We exclude demos if they are redundant or flaky etc. The logic for this exclusion is handled (like the composition) in
./index.js
If you introduce new behavior, prefer adding a demo to the documentation to solve documentation and testing with one file. If you're adding a new test prefer a new component instead of editing existing files since that might unknowingly alter existing tests.
yarn test:regressions:dev
will build all fixtures and render an overview page that lists all fixtures.
This can be used to debug individual fixtures.
By default, a devtools-like view is shown that can be disabled by appending #no-dev
to the URL e.g. http://localhost:3000/docs-customization-typography/CustomResponsiveFontSizes#no-dev
or forced by appending #dev
to the URL e.g. http://localhost:3000/docs-customization-typography/CustomResponsiveFontSizes#dev
.
We're using playwright
to iterate over each fixture and take a screenshot.
It allows catching regressions like this one:
Screenshots are saved in ./screenshots/$BROWSER_NAME/
.
Each test tests only a single fixture.
A fixture can be loaded with await renderFixture(fixturePath)
e.g. renderFixture('Unstable_TrapFocus/OpenTrapFocus')
.
For development yarn test:regressions:dev
and yarn test:regressions:run --watch
in separate terminals is recommended.
command | description |
---|---|
yarn test:regressions |
Full run |
yarn test:regressions:dev |
Prepares the fixtures to be able to test in watchmode |
yarn test:regressions:run |
Runs the tests (requires yarn test:regressions:dev or yarn test:regressions:build +yarn test:regressions:server ) |
yarn test:regressions:build |
Builds the webpack bundle for viewing the fixtures |
yarn test:regressions:server |
Serves the fixture bundle. |