-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add visual regression testing section to the examples (#621)
- Loading branch information
1 parent
a430ca4
commit 510999f
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Lost Pixel visual regression testing | ||
|
||
Lost Pixel is a [modern open-source visual regression testing tool](https://github.com/lost-pixel/lost-pixel) that allows you to run self-hosted visual regression tests. [Lost Pixel Platofrm](https://lost-pixel.com) is for teams and is a cloud version of visual testing. | ||
|
||
## Setting up self-hosted visual testing | ||
|
||
Lost Pixel has first-class Histoire support meaning that you don't need to do much to add visual tests to your app if you have your Histoire book ready! | ||
|
||
Start with installing lost-pixel by `npm install lost-pixel` and creating a `lostpixel.config.js|ts` file with following contents. | ||
|
||
```javascript | ||
import { CustomProjectConfig } from 'lost-pixel'; | ||
|
||
export const config: CustomProjectConfig = { | ||
histoireShots: { | ||
histoireUrl: './.histoire/dist', | ||
}, | ||
generateOnly: true, | ||
failOnDifference: true | ||
}; | ||
``` | ||
**Before running visual tests you need to have your Histoire book built first**. | ||
|
||
This setup allows you to run visual tests locally. To test your stories run `npx lost-pixel` | ||
|
||
To update the baselines run `npx lost-pixel update`. | ||
|
||
## GitHub actions | ||
|
||
To run your tests on CI you can use lost-pixel action utility. If you are running on any other CI provider - lost-pixel is a [docker image](https://hub.docker.com/r/lostpixel/lost-pixel) that is runnable on CI of your choice(only **within GitHub** currently though) | ||
|
||
```yaml | ||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: 'npm' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build histoire | ||
run: npm run story:build | ||
|
||
- name: Lost Pixel | ||
uses: lost-pixel/[email protected] | ||
``` | ||
To update baselines locally run `npx lost-pixel docker update`, this will ensure that lost-pixel runs in docker and there are no OS differences in rendering between CI and local tests. | ||
|
||
## Lost Pixel Platform | ||
|
||
If you have self-hosted version of tests working it is not complicated to migrate to Lost Pixel Platform. Follow [this guide](https://docs.lost-pixel.com/user-docs/setup/lost-pixel-platform) to achieve that. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Histoire Screenshot with Percy for visual regression testing | ||
|
||
You need the [Percy CLI](https://docs.percy.io/docs/cli-overview) installed to be able to send snapshots to Percy. | ||
|
||
|
||
```bash | ||
pnpm add -D @histoire/plugin-percy | ||
``` | ||
|
||
Add the plugin in histoire config: | ||
|
||
```js | ||
import { defineConfig } from 'histoire' | ||
import { HstPercy } from '@histoire/plugin-percy' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
HstPercy({ | ||
// Options here | ||
}), | ||
], | ||
}) | ||
``` | ||
|
||
Then use the Percy CLI | ||
|
||
```bash | ||
# Replace `story:build` with the script to build the stories if you changed it | ||
percy exec pnpm run story:build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters