Skip to content

Commit 4759170

Browse files
committed
test: Introduce Chromatic for Visual Regression Tests
1 parent 412de7e commit 4759170

21 files changed

Lines changed: 139 additions & 1 deletion

.github/workflows/chromatic.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Workflow name
2+
name: 'Chromatic'
3+
4+
# Event for the workflow
5+
on: push
6+
7+
# List of jobs
8+
jobs:
9+
chromatic-deployment:
10+
# Operating System
11+
runs-on: ubuntu-latest
12+
# Job steps
13+
steps:
14+
- uses: actions/checkout@v1
15+
- name: Install dependencies
16+
# 👇 Install dependencies with the same package manager used in the project (replace it as needed) e.g. yarn, npm, pnpm
17+
run: npm install
18+
# 👇 Adds Chromatic as a step in the workflow
19+
- name: Publish to Chromatic
20+
uses: chromaui/action@v1
21+
# Chromatic GitHub Action options
22+
with:
23+
# 👇 Chromatic projectToken, refer to the manage page to obtain it.
24+
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
25+
skip: dependabot/**
26+
onlyChanged: true

.storybook/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module.exports = {
44
stories: ['../src/**/*.stories.@(tsx|mdx)', '../stories/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
55
siteUrl: 'https://github.com/Doist/reactist',
66
features: {
7+
// Needed for Chromatic/Storybooks interactive tests
78
// See https://storybook.js.org/docs/react/writing-tests/interaction-testing
9+
// See https://www.chromatic.com/docs/interactions#how-to-write-interaction-tests
810
interactionsDebugger: true,
911
},
1012
addons: [

.storybook/preview.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export const parameters = {
1313
},
1414
},
1515
decorators,
16+
chromatic: {
17+
// This allows us to opt-in to Chromatic snapshots per story
18+
// See https://www.chromatic.com/docs/ignoring-elements#ignore-stories
19+
disableSnapshot: true,
20+
},
1621
}
1722

1823
const badgeFontStyles = {

package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"autoprefixer": "^9.8.0",
9797
"babel-core": "^7.0.0-bridge.0",
9898
"babel-loader": "^8.1.0",
99+
"chromatic": "^6.11.4",
99100
"classnames": "^2.2.5",
100101
"css-loader": "^4.2.2",
101102
"cssnano": "^4.1.10",

src/new-components/alert/alert.stories.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ A simple Alert component.
4949
name="Main demo"
5050
parameters={{
5151
docs: { source: { type: 'code' } },
52+
chromatic: { disableSnapshot: false },
5253
}}
5354
>
5455
<Stack space="xxlarge">

src/new-components/badge/badge.stories.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The use of variants does not provide extra semantic meaning and is strictly visu
2121
<Story
2222
parameters={{
2323
docs: { source: { type: 'code' } },
24+
chromatic: { disableSnapshot: false },
2425
}}
2526
name="Main demo"
2627
>

src/new-components/button/button.stories.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ A semantic button that provides all the necessary visual variants. It follows th
3636
name="Main demo"
3737
parameters={{
3838
docs: { source: { type: 'code' } },
39+
chromatic: { disableSnapshot: false },
3940
}}
4041
>
4142
<Stack space="xxlarge">
@@ -153,6 +154,7 @@ this is discouraged, and not guaranteed to be supported in the future.
153154
name="With label and icon"
154155
parameters={{
155156
docs: { source: { type: 'code' } },
157+
chromatic: { disableSnapshot: false },
156158
}}
157159
>
158160
<Stack space="xxlarge">
@@ -223,6 +225,7 @@ as a tooltip if no tooltip is provided.
223225
name="Icon-only buttons"
224226
parameters={{
225227
docs: { source: { type: 'code' } },
228+
chromatic: { disableSnapshot: false },
226229
}}
227230
>
228231
<Stack space="large">
@@ -268,6 +271,7 @@ for this purpose.
268271
name="With different size"
269272
parameters={{
270273
docs: { source: { type: 'code' } },
274+
chromatic: { disableSnapshot: false },
271275
}}
272276
>
273277
<Stack space="xxlarge">
@@ -531,6 +535,7 @@ export function FullWidthTemplate({ label, ...otherProps }) {
531535
name="Full-width"
532536
parameters={{
533537
docs: { source: { type: 'code' } },
538+
chromatic: { disableSnapshot: false },
534539
}}
535540
argTypes={{
536541
label: {

src/new-components/checkbox-field/checkbox-field.stories.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ A checkbox field with a `ReactNode` as label.
131131
name="Indeterminate Example"
132132
parameters={{
133133
docs: { source: { type: 'dynamic' } },
134+
chromatic: { disableSnapshot: false },
134135
}}
135136
>
136137
{() => {

src/new-components/heading/heading.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export function HeadingStory() {
6969
)
7070
}
7171

72+
HeadingStory.parameters = {
73+
chromatic: { disableSnapshot: false },
74+
}
75+
7276
export function TruncatedHeadingStory() {
7377
return (
7478
<section className="story">
@@ -87,6 +91,10 @@ export function TruncatedHeadingStory() {
8791
)
8892
}
8993

94+
TruncatedHeadingStory.parameters = {
95+
chromatic: { disableSnapshot: false },
96+
}
97+
9098
export function ResponsiveHeadingStory(props: React.ComponentProps<typeof Heading>) {
9199
return (
92100
<>

0 commit comments

Comments
 (0)