Skip to content
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

Update CSS Module contribution doc to include adding new VRT #5205

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions contributor-docs/migrating-to-css-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ This guide outlines the steps to follow when refactoring Primer React components

- **Verify VRT (Visual Regression Testing) Coverage:**
- Check for missing VRT coverage. We utilize the VRT tests to make sure we're matching styling in production with current expectations. Components should have a Storybook story for every "feature" or option available that impacts the UI for VRT to capture in a screenshot.
- Make sure there are `dev` stories for any edge cases spotted in production for the component (ie. `sx` prop, custom className, styled system attributes). `dev` stories may include things that we wouldn't normally recommend for the purpose of stress testing what happens when PRC components are overridden with custom styles.
- **Ensure All Visual Changes Are Completed:**
- Make necessary visual changes **before** creating the CSS Modules refactor PR.

Expand Down Expand Up @@ -121,11 +120,65 @@ This guide outlines the steps to follow when refactoring Primer React components
expect(render(<FeatureFlagElement />).container.firstChild).toHaveClass('test-class-name')
})
```
- **Regression Testing:**
- Validate that no visual regressions occur when the feature flag is enabled. The `vrt*` tests are setup to compare the feature flagged component with the original component and will fail if there is a mismatch.
- **Handling `sx` Prop:**
- Confirm the `sx` prop behaves correctly with the feature flag enabled.

#### Visual regression testing

Validate that no visual regressions occur when the feature flag is enabled. The `vrt*` tests are setup to compare the feature flagged component with the original component and will fail if there is a mismatch.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea! Would we want to make sure we mark them to be removed once the CSS module migration is complete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to keep the dev tests around because they are testing for className override support mainly. When the feature flags are all removed we will then remove the check for enabled vs. default, but we can do that all at once probably since each test uses the same configuration


- Add `dev` stories for any edge cases spotted in production for the component (ie. `sx` prop, custom className, styled system attributes). `dev` stories may include things that we wouldn't normally recommend for the purpose of stress testing what happens when PRC components are overridden with custom styles.
- Setup VRT tests for `dev` stories. Copy an existing test in the corresponding test file in the [e2e directory](https://github.com/primer/react/tree/main/e2e/components) and update the id to match the new `dev` story.

Example test file:

```ts
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

const stories = [
{
title: 'Dev: Test color',
id: 'components-{componentname}-dev--customcolor',
},
] as const

test.describe('ComponentName', () => {
for (const story of stories) {
test.describe(story.title, () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`ComponentName.${story.title}.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
}
})
```

---

## Releasing a Component
Expand Down
Loading