Skip to content

Commit 61214ef

Browse files
HarkunwarmanishprivetWai.Tungshanpriyanmikeesto
committed
test(snapshot): Migrate snapshot tests to storybook (#5340)
Co-authored-by: Manish Kumar ⛄ <[email protected]> Co-authored-by: Wai.Tung <[email protected]> Co-authored-by: Shanmughapriyan S <[email protected]> Co-authored-by: Michael Esteban <[email protected]> Co-authored-by: Claudio Wunder <[email protected]> Co-authored-by: Teja Sai Sandeep Reddy Konala <[email protected]> Co-authored-by: Claudio Wunder <[email protected]> Co-authored-by: vasanth9 <cheepurupalli.vasanthkumar.com> Co-authored-by: Aymen Naghmouchi <[email protected]> Co-authored-by: Teja Sai Sandeep Reddy Konala <[email protected]> Co-authored-by: Augustin Mauroy <[email protected]> Co-authored-by: Guilherme Araújo <[email protected]> Co-authored-by: Augustin Mauroy <[email protected]> Co-authored-by: HinataKah0 <[email protected]> Co-authored-by: Olaleye Blessing <[email protected]> Co-authored-by: ktssr <[email protected]> Co-authored-by: vasanthkumar <[email protected]> Co-authored-by: Floran Hachez <[email protected]> Co-authored-by: Jatin <[email protected]> fixed styleling misconfig and fixed storybooks (#5281) fix storybook styles, imports, typescript config and dependencies (#5319 fix(package.json) Lint command is missing slashes (#5321 fix storybook local development mode (#5335) fix(i18n): translation key (#5347)
1 parent bf9e2fc commit 61214ef

File tree

53 files changed

+3967
-1168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3967
-1168
lines changed

.github/workflows/pull-request.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ jobs:
8383
enableCrossOsArchive: true
8484

8585
- name: Run Unit Tests
86-
run: npx turbo test:ci
86+
run: npx turbo test:unit -- --coverage
87+
env:
88+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
89+
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
90+
91+
- name: Run Storybook Tests
92+
run: npx turbo test:storybook
8793
env:
8894
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
8995
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

.storybook/preview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export const decorators = [
3939
}
4040
`}
4141
</style>
42-
<Story />
42+
<div data-test-id="story-root">
43+
<Story />
44+
</div>
4345
</NodeDataProvider>
4446
</LocaleProvider>
4547
</SiteProvider>

.storybook/test-runner.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// TODO: Convert this to ESM once the bug is resolved
2+
// https://github.com/storybookjs/test-runner/issues/293
3+
4+
const config = {
5+
async postRender(page, _context) {
6+
const rootElementId = '[data-test-id="story-root"]';
7+
const rootElement = await page.locator(rootElementId);
8+
const content = await rootElement.innerHTML();
9+
expect(content).toBeDefined();
10+
expect(content).toMatchSnapshot();
11+
},
12+
};
13+
14+
module.exports = config;

CONTRIBUTING.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ We also offer other commands that offer you assistance during your local develop
103103
- **Usage:** `npx turbo scripts:release-post -- --version=vXX.X.X --force`
104104
- `npx turbo storybook` starts Storybook's local server
105105
- `npx turbo storybook:build` builds Storybook as a static web application for publishing
106-
- `npx turbo test` runs jest (unit-tests) locally
106+
- `npx turbo test` runs all tests locally
107+
- `npx turbo test:unit` runs jest (unit-tests) locally
108+
- `npx turbo test:storybook` runs storybook test-runner tests
109+
- `npx turbo test:storybook:snapshot` generates and updates snapshots for all storybook components.
107110

108111
## Vocabulary
109112

@@ -185,7 +188,7 @@ Commits should be signed. You can read more about [Commit Signing][] here.
185188

186189
Each new feature or bug fix should be accompanied by a unit test (when deemed valuable). We use [Jest][] as our test runner and [React Testing Library][] for our React unit tests.
187190

188-
We also use [Storybook][] to document our components. Each component should have a storybook story that documents the component's usage.
191+
We also use [Storybook][] to document our components. Each component should have a storybook story that documents the component's usage. Snapshot testing of our components is directly done by taking snapshot of all Storybook stories, using [Storybook Test Runner][] and [Playwright][].
189192

190193
### General Guidelines for Unit Tests
191194

@@ -300,6 +303,8 @@ If something is missing here, or you feel something is not well described, feel
300303
[Jest]: https://jestjs.io/
301304
[React Testing Library]: https://testing-library.com/docs/react-testing-library/intro/
302305
[Storybook]: https://storybook.js.org/
306+
[Storybook Test Runner]: https://storybook.js.org/addons/@storybook/test-runner#dom-snapshot-recipe
307+
[Playwright]: https://playwright.dev/
303308
[`react-intl`]: https://formatjs.io/docs/react-intl/
304309
[Next.js]: https://nextjs.org/
305310
[MDX]: https://mdxjs.com/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Api/DataTag Blue smoke-test 1`] = `
4+
<span class="DataTag_dataTag__xyqF4"
5+
data-tag="M"
6+
>
7+
M
8+
</span>
9+
`;
10+
11+
exports[`Api/DataTag Red smoke-test 1`] = `
12+
<span class="DataTag_dataTag__xyqF4"
13+
data-tag="E"
14+
>
15+
E
16+
</span>
17+
`;
18+
19+
exports[`Api/DataTag Yellow smoke-test 1`] = `
20+
<span class="DataTag_dataTag__xyqF4"
21+
data-tag="C"
22+
>
23+
C
24+
</span>
25+
`;

components/Api/DataTag/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 0 additions & 34 deletions
This file was deleted.

components/Api/DataTag/__tests__/index.test.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Article/Alert Default smoke-test 1`] = `
4+
<div class="Alert_alert__qjYPQ">
5+
This is an alert
6+
</div>
7+
`;

components/Article/Alert/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 0 additions & 19 deletions
This file was deleted.

components/Article/Alert/__tests__/index.test.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)