git checkout ut-15-visual-regression-testing-boilerplate
yarn
- Create library with storybook.
# Create a library.
yarn nx g @nrwl/angular:library animal-ui
# Install Nx Storybook plugin.
yarn add -D @nrwl/storybook
# Setup storybook & cypress.
yarn nx g storybook-configuration animal-ui --configure-cypress --no-generate-stories --no-generate-cypress-specs
-
Setup
cypress-image-snapshot
(Cf. https://github.com/palmerhq/cypress-image-snapshot#installation) -
Set image snapshots folder in
support/commands.ts
.
addMatchImageSnapshotCommand({
customSnapshotsDir: 'src/snapshots',
});
- Fix viewport size in
cypress.json
.
{
...
"viewportHeight": 768,
"viewportWidth": 1024
}
yarn e2e animal-ui-e2e --watch
Watch your changes on http://localhost:4400
-
Add an
animal
input. -
Add Storybook knobs in
animal-preview.stories.ts
.
import { text, ... } from '@storybook/addon-knobs';
export const main = () => ({
...
props: {
name: text('name', 'Dolly')
}
});
-
Display a card with a different icon depending on animal type.
-
Show price if present.
You can control knobs by adding knob-x=y
to the query string.