|
| 1 | +# react-text-visual-regression |
| 2 | + |
| 3 | +This library was generated with [Nx](https://nx.dev). |
| 4 | + |
| 5 | +## Building |
| 6 | + |
| 7 | +Run `nx build react-text-visual-regression` to build the library. |
| 8 | + |
| 9 | +## Running visual regression |
| 10 | + |
| 11 | +Run `nx run react-text-visual-regression:test-vr-cli`. |
| 12 | + |
| 13 | +## About |
| 14 | + |
| 15 | +Project for visual regression scenarios. |
| 16 | + |
| 17 | +> Uses Free, Secure and OSS VR testing solution based on: |
| 18 | +> |
| 19 | +> - Storybook to author VR scenarios |
| 20 | +> - StoryWright for capturing Stories and their interactions |
| 21 | +> - Visual Regression Assert CLI - to execute diffing and updating snapshots baseline |
| 22 | +
|
| 23 | +## Authoring VR scenarios |
| 24 | + |
| 25 | +1. write stories following Storybook CSF3 format |
| 26 | + |
| 27 | +```ts |
| 28 | +import { Steps, type StoryParameters } from 'storywright'; |
| 29 | + |
| 30 | +export default { |
| 31 | + title: 'Text Converged', |
| 32 | + // 1. Define decorators to create scoped images that won't change dimensions over time |
| 33 | + decorators: [ |
| 34 | + Story => ( |
| 35 | + <div className="testWrapper" style={{ width: '250px' }}> |
| 36 | + <Story /> |
| 37 | + </div> |
| 38 | + ), |
| 39 | + ], |
| 40 | + // 2. If interactions are needed , define those via StoryWright Steps API |
| 41 | + parameters: { |
| 42 | + storyWright: { steps: new Steps().snapshot('normal', { cropTo: '.testWrapper' }).end() }, |
| 43 | + } satisfies StoryParameters, |
| 44 | +} satisfies Meta<typeof Text>; |
| 45 | +``` |
| 46 | + |
| 47 | +2. Override steps per story if needed |
| 48 | + |
| 49 | +```ts |
| 50 | +export const Default = { |
| 51 | + name: 'Default', |
| 52 | + render: () => { |
| 53 | + return <div>markup</div>; |
| 54 | + }, |
| 55 | + // 1. overriding default export steps - this story will execute different behaviors |
| 56 | + parameters: { |
| 57 | + storyWright: { steps: new Steps().click().snapshot('normal').end() }, |
| 58 | + } satisfies StoryParameters, |
| 59 | +} satisfies StoryObj; |
| 60 | +``` |
| 61 | + |
| 62 | +3. leverage `@fluentui/visual-regression-utilities` to create scenarios for Right to Left, Dark Mode, High Contrast Mode etc |
| 63 | + |
| 64 | +```ts |
| 65 | +export const Default = { |
| 66 | + // 1. name is mandatory to properly propagate it to getStoryVariant fn call |
| 67 | + name: 'Default', |
| 68 | + render: () => { |
| 69 | + return <div>markup</div>; |
| 70 | + }, |
| 71 | +} satisfies StoryObj; |
| 72 | + |
| 73 | +// 2. create new Variants of your scenario |
| 74 | +export const DefaultRTL = getStoryVariant(Default, RTL); |
| 75 | +``` |
0 commit comments