-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-text-vr): bootstrap visual-regression project #34030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Hotell
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
Hotell:vrt/migrate-react-text
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
packages/react-components/react-text/visual-regression/.eslintrc.json
This file contains hidden or 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 @@ | ||
| { | ||
| "extends": ["../../../../.eslintrc.json"], | ||
| "ignorePatterns": ["!**/*"], | ||
| "overrides": [ | ||
| { | ||
| "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["*.ts", "*.tsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["*.js", "*.jsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["*.json"], | ||
| "parser": "jsonc-eslint-parser", | ||
| "rules": { | ||
| "@nx/dependency-checks": [ | ||
| "error", | ||
| { | ||
| "ignoredFiles": ["{projectRoot}/eslint.config.{js,cjs,mjs}"] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } |
58 changes: 58 additions & 0 deletions
58
packages/react-components/react-text/visual-regression/.storybook/main.js
This file contains hidden or 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,58 @@ | ||
| const path = require('path'); | ||
|
|
||
| const { registerTsPaths, registerRules, rules, loadWorkspaceAddon } = require('@fluentui/scripts-storybook'); | ||
| const tsConfigPath = path.resolve(__dirname, '../../../../../tsconfig.base.json'); | ||
|
|
||
| module.exports = /** @type {import('@storybook/react-webpack5').StorybookConfig} */ ({ | ||
| addons: [loadWorkspaceAddon('@fluentui/react-storybook-addon', { tsConfigPath })], | ||
| stories: ['../src/**/*.stories.tsx'], | ||
| core: { | ||
| disableTelemetry: true, | ||
| }, | ||
| framework: { | ||
| name: '@storybook/react-webpack5', | ||
| options: { | ||
| builder: { | ||
| useSWC: true, | ||
| lazyCompilation: false, | ||
| }, | ||
| }, | ||
| }, | ||
| typescript: { | ||
| // disable react-docgen-typescript (totally not needed here, slows things down a lot) | ||
| reactDocgen: false, | ||
| }, | ||
| webpackFinal: (config, options) => { | ||
| if (options.configType === 'PRODUCTION') { | ||
| // Disable source maps | ||
| config.devtool = false; | ||
| } | ||
| registerTsPaths({ config, configFile: tsConfigPath }); | ||
| registerRules({ config, rules: [rules.griffelRule] }); | ||
|
|
||
| return config; | ||
| }, | ||
| swc() { | ||
| return { | ||
| jsc: { | ||
| target: 'es2019', | ||
| parser: { | ||
| syntax: 'typescript', | ||
| tsx: true, | ||
| decorators: true, | ||
| dynamicImport: true, | ||
| }, | ||
| transform: { | ||
| decoratorMetadata: true, | ||
| legacyDecorator: true, | ||
| }, | ||
| keepClassNames: true, | ||
| externalHelpers: true, | ||
| loose: true, | ||
| minify: { | ||
| mangle: false, | ||
| }, | ||
| }, | ||
| }; | ||
| }, | ||
| }); |
8 changes: 8 additions & 0 deletions
8
packages/react-components/react-text/visual-regression/.storybook/preview.js
This file contains hidden or 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,8 @@ | ||
| /** @type {import("@fluentui/react-storybook-addon").FluentParameters} */ | ||
| export const parameters = { | ||
| layout: 'none', | ||
| mode: 'vr-test', | ||
| reactStorybookAddon: { | ||
| disabledDecorators: ['AriaLive'], | ||
| }, | ||
| }; |
10 changes: 10 additions & 0 deletions
10
packages/react-components/react-text/visual-regression/.storybook/tsconfig.json
This file contains hidden or 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,10 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "", | ||
| "allowJs": true, | ||
| "checkJs": true, | ||
| "types": ["static-assets", "environment"] | ||
| }, | ||
| "include": ["*.js"] | ||
| } |
75 changes: 75 additions & 0 deletions
75
packages/react-components/react-text/visual-regression/README.md
This file contains hidden or 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,75 @@ | ||
| # react-text-visual-regression | ||
|
|
||
| This library was generated with [Nx](https://nx.dev). | ||
|
|
||
| ## Building | ||
|
|
||
| Run `nx build react-text-visual-regression` to build the library. | ||
|
|
||
| ## Running visual regression | ||
|
|
||
| Run `nx run react-text-visual-regression:test-vr-cli`. | ||
|
|
||
| ## About | ||
|
|
||
| Project for visual regression scenarios. | ||
|
|
||
| > Uses Free, Secure and OSS VR testing solution based on: | ||
| > | ||
| > - Storybook to author VR scenarios | ||
| > - StoryWright for capturing Stories and their interactions | ||
| > - Visual Regression Assert CLI - to execute diffing and updating snapshots baseline | ||
|
|
||
| ## Authoring VR scenarios | ||
|
|
||
| 1. write stories following Storybook CSF3 format | ||
|
|
||
| ```ts | ||
| import { Steps, type StoryParameters } from 'storywright'; | ||
|
|
||
| export default { | ||
| title: 'Text Converged', | ||
| // 1. Define decorators to create scoped images that won't change dimensions over time | ||
| decorators: [ | ||
| Story => ( | ||
| <div className="testWrapper" style={{ width: '250px' }}> | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| ], | ||
| // 2. If interactions are needed , define those via StoryWright Steps API | ||
| parameters: { | ||
| storyWright: { steps: new Steps().snapshot('normal', { cropTo: '.testWrapper' }).end() }, | ||
| } satisfies StoryParameters, | ||
| } satisfies Meta<typeof Text>; | ||
| ``` | ||
|
|
||
| 2. Override steps per story if needed | ||
|
|
||
| ```ts | ||
| export const Default = { | ||
| name: 'Default', | ||
| render: () => { | ||
| return <div>markup</div>; | ||
| }, | ||
| // 1. overriding default export steps - this story will execute different behaviors | ||
| parameters: { | ||
| storyWright: { steps: new Steps().click().snapshot('normal').end() }, | ||
| } satisfies StoryParameters, | ||
| } satisfies StoryObj; | ||
| ``` | ||
|
|
||
| 3. leverage `@fluentui/visual-regression-utilities` to create scenarios for Right to Left, Dark Mode, High Contrast Mode etc | ||
|
|
||
| ```ts | ||
| export const Default = { | ||
| // 1. name is mandatory to properly propagate it to getStoryVariant fn call | ||
| name: 'Default', | ||
| render: () => { | ||
| return <div>markup</div>; | ||
| }, | ||
| } satisfies StoryObj; | ||
|
|
||
| // 2. create new Variants of your scenario | ||
| export const DefaultRTL = getStoryVariant(Default, RTL); | ||
| ``` |
19 changes: 19 additions & 0 deletions
19
packages/react-components/react-text/visual-regression/package.json
This file contains hidden or 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,19 @@ | ||
| { | ||
| "name": "@fluentui/react-text-visual-regression", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@fluentui/react-text": "*", | ||
| "@fluentui/visual-regression-utilities": "*" | ||
| }, | ||
| "peerDependencies": { | ||
| "@storybook/react": "^7.6.20" | ||
| }, | ||
| "devDependencies": { | ||
| "@fluentui/react-storybook-addon": "*", | ||
| "@fluentui/scripts-storybook": "*" | ||
| }, | ||
| "type": "commonjs", | ||
| "main": "./src/index.js", | ||
| "typings": "./src/index.d.ts" | ||
| } |
49 changes: 49 additions & 0 deletions
49
packages/react-components/react-text/visual-regression/project.json
This file contains hidden or 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,49 @@ | ||
| { | ||
| "name": "react-text-visual-regression", | ||
| "$schema": "../../../../node_modules/nx/schemas/project-schema.json", | ||
| "sourceRoot": "packages/react-components/react-text/visual-regression/src", | ||
| "projectType": "library", | ||
| "tags": ["vNext", "platform:web", "visual-regression"], | ||
| "targets": { | ||
| "build-storybook": { | ||
| "command": "storybook build -o dist/storybook --quiet", | ||
| "options": { | ||
| "cwd": "{projectRoot}" | ||
| } | ||
| }, | ||
| "generate-image-for-vrt": { | ||
| "command": "rm -rf dist/vrt/actual && storywright --browsers chromium --url dist/storybook --destpath dist/vrt/actual --waitTimeScreenshot 500 --concurrency 4 --headless true", | ||
| "options": { | ||
| "cwd": "{projectRoot}" | ||
| }, | ||
| "metadata": { | ||
| "help": { | ||
| "command": "yarn storywright --help", | ||
| "example": {} | ||
| } | ||
| }, | ||
| "dependsOn": ["build-storybook"], | ||
| "inputs": ["{projectRoot}/src/**/*.stories.tsx"], | ||
| "outputs": ["{projectRoot}/dist/vrt/actual/**"], | ||
| "cache": true | ||
| }, | ||
| "test-vr-cli": { | ||
| "command": "visual-regression-assert assert --baselineDir src/__snapshots__ --outputPath dist/vrt", | ||
| "options": { | ||
| "cwd": "{projectRoot}" | ||
| }, | ||
| "dependsOn": [ | ||
| "build-storybook", | ||
| "generate-image-for-vrt", | ||
| { "projects": ["visual-regression-assert"], "target": "build" } | ||
| ], | ||
| "inputs": ["{projectRoot}/dist/vrt/screenshots/**", "{projectRoot}/src/**/*.stories.tsx"], | ||
| "metadata": { | ||
| "help": { | ||
| "command": "yarn visual-regression-assert --help", | ||
| "example": {} | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕵🏾♀️ visual regressions to review in the fluentuiv8 Visual Regression Report
Keytip 1 screenshots
react-charting-AreaChart 1 screenshots
react-charting-VerticalBarChart 1 screenshots