-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24645 from storybookjs/docs_test_runner_updates
Docs: Test runner minor fixes
- v9.0.0-alpha.2
- v9.0.0-alpha.1
- v9.0.0-alpha.0
- v8.7.0-alpha.0
- v8.6.4
- v8.6.3
- v8.6.2
- v8.6.1
- v8.6.0
- v8.6.0-beta.10
- v8.6.0-beta.9
- v8.6.0-beta.8
- v8.6.0-beta.7
- v8.6.0-beta.6
- v8.6.0-beta.5
- v8.6.0-beta.4
- v8.6.0-beta.3
- v8.6.0-beta.2
- v8.6.0-beta.1
- v8.6.0-beta.0
- v8.6.0-alpha.5
- v8.6.0-alpha.4
- v8.6.0-alpha.3
- v8.6.0-alpha.2
- v8.6.0-alpha.1
- v8.6.0-alpha.0
- v8.5.8
- v8.5.7
- v8.5.6
- v8.5.5
- v8.5.4
- v8.5.3
- v8.5.2
- v8.5.1
- v8.5.0
- v8.5.0-beta.11
- v8.5.0-beta.10
- v8.5.0-beta.9
- v8.5.0-beta.8
- v8.5.0-beta.7
- v8.5.0-beta.6
- v8.5.0-beta.5
- v8.5.0-beta.4
- v8.5.0-beta.3
- v8.5.0-beta.2
- v8.5.0-beta.1
- v8.5.0-beta.0
- v8.5.0-alpha.22
- v8.5.0-alpha.21
- v8.5.0-alpha.20
- v8.5.0-alpha.19
- v8.5.0-alpha.18
- v8.5.0-alpha.17
- v8.5.0-alpha.16
- v8.5.0-alpha.15
- v8.5.0-alpha.14
- v8.5.0-alpha.13
- v8.5.0-alpha.12
- v8.5.0-alpha.11
- v8.5.0-alpha.10
- v8.5.0-alpha.9
- v8.5.0-alpha.8
- v8.5.0-alpha.7
- v8.5.0-alpha.6
- v8.5.0-alpha.5
- v8.5.0-alpha.4
- v8.5.0-alpha.3
- v8.5.0-alpha.2
- v8.5.0-alpha.1
- v8.5.0-alpha.0
- v8.4.7
- v8.4.6
- v8.4.5
- v8.4.4
- v8.4.3
- v8.4.2
- v8.4.1
- v8.4.0
- v8.4.0-beta.5
- v8.4.0-beta.4
- v8.4.0-beta.3
- v8.4.0-beta.2
- v8.4.0-beta.1
- v8.4.0-beta.0
- v8.4.0-alpha.8
- v8.4.0-alpha.7
- v8.4.0-alpha.6
- v8.4.0-alpha.5
- v8.4.0-alpha.4
- v8.4.0-alpha.3
- v8.4.0-alpha.2
- v8.4.0-alpha.1
- v8.4.0-alpha.0
- v8.3.7
- v8.3.6
- v8.3.5
- v8.3.4
- v8.3.3
- v8.3.2
- v8.3.1
- v8.3.0
- v8.3.0-beta.5
- v8.3.0-beta.4
- v8.3.0-beta.3
- v8.3.0-beta.2
- v8.3.0-beta.1
- v8.3.0-beta.0
- v8.3.0-alpha.11
- v8.3.0-alpha.10
- v8.3.0-alpha.9
- v8.3.0-alpha.8
- v8.3.0-alpha.7
- v8.3.0-alpha.6
- v8.3.0-alpha.5
- v8.3.0-alpha.4
- v8.3.0-alpha.3
- v8.3.0-alpha.2
- v8.3.0-alpha.1
- v8.3.0-alpha.0
- v8.2.10
- v8.2.9
- v8.2.8
- v8.2.7
- v8.2.6
- v8.2.5
- v8.2.4
- v8.2.3
- v8.2.2
- v8.2.1
- v8.2.0
- v8.2.0-beta.3
- v8.2.0-beta.2
- v8.2.0-beta.1
- v8.2.0-beta.0
- v8.2.0-alpha.10
- v8.2.0-alpha.9
- v8.2.0-alpha.8
- v8.2.0-alpha.7
- v8.2.0-alpha.6
- v8.2.0-alpha.5
- v8.2.0-alpha.4
- v8.2.0-alpha.3
- v8.2.0-alpha.2
- v8.2.0-alpha.1
- v8.2.0-alpha.0
- v8.1.11
- v8.1.10
- v8.1.9
- v8.1.8
- v8.1.7
- v8.1.6
- v8.1.5
- v8.1.4
- v8.1.3
- v8.1.2
- v8.1.1
- v8.1.0
- v8.1.0-beta.1
- v8.1.0-beta.0
- v8.1.0-alpha.8
- v8.1.0-alpha.7
- v8.1.0-alpha.6
- v8.1.0-alpha.5
- v8.1.0-alpha.4
- v8.1.0-alpha.3
- v8.1.0-alpha.2
- v8.1.0-alpha.1
- v8.1.0-alpha.0
- v8.0.10
- v8.0.9
- v8.0.8
- v8.0.7
- v8.0.6
- v8.0.5
- v8.0.4
- v8.0.3
- v8.0.2
- v8.0.1
- v8.0.0
- v8.0.0-rc.5
- v8.0.0-rc.4
- v8.0.0-rc.3
- v8.0.0-rc.2
- v8.0.0-rc.1
- v8.0.0-rc.0
- v8.0.0-beta.6
- v8.0.0-beta.5
- v8.0.0-beta.4
- v8.0.0-beta.3
- v8.0.0-beta.2
- v8.0.0-beta.1
- v8.0.0-beta.0
- v8.0.0-alpha.17
- v8.0.0-alpha.16
- v8.0.0-alpha.15
- v8.0.0-alpha.14
- v8.0.0-alpha.13
- v8.0.0-alpha.12
- v8.0.0-alpha.11
- v8.0.0-alpha.10
- v8.0.0-alpha.9
- v8.0.0-alpha.8
- v8.0.0-alpha.7
- v8.0.0-alpha.6
- v8.0.0-alpha.5
- v8.0.0-alpha.4
- v8.0.0-alpha.3
- v8.0.0-alpha.2
- v8.0.0-alpha.1
- v8.0.0-alpha.0
- v7.6.19
- v7.6.18
- v7.6.17
- v7.6.16
- v7.6.15
- v7.6.14
- v7.6.13
- v7.6.12
- v7.6.11
- v7.6.10
- v7.6.9
- v7.6.8
- v7.6.7
- v7.6.6
- v7.6.5
- v7.6.4
- v7.6.3
- v7.6.2
- v7.6.1
- v7.6.0
- v7.6.0-beta.2
- v7.6.0-beta.1
- v7.6.0-beta.0
- v7.6.0-alpha.7
- 7.6.20
Showing
32 changed files
with
582 additions
and
95 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
docs/snippets/common/my-component-exclude-tags.story.js.mdx
This file contains 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,15 @@ | ||
```js | ||
// MyComponent.stories.js|jsx | ||
|
||
import { MyComponent } from './MyComponent'; | ||
|
||
export default { | ||
component: MyComponent, | ||
tags: ['no-tests'], // 👈 Provides the `no-tests` tag to all stories in this file | ||
}; | ||
|
||
export const ExcludeStory = { | ||
//👇 Adds the `no-tests` tag to this story to exclude it from the tests when enabled in the test-runner configuration | ||
tags: ['no-tests'], | ||
}; | ||
``` |
21 changes: 21 additions & 0 deletions
21
docs/snippets/common/my-component-exclude-tags.story.ts.mdx
This file contains 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,21 @@ | ||
```ts | ||
// MyComponent.stories.ts|tsx | ||
|
||
// Replace your-framework with the name of your framework | ||
import type { Meta, StoryObj } from '@storybook/your-framework'; | ||
|
||
import { MyComponent } from './MyComponent'; | ||
|
||
const meta: Meta<typeof MyComponent> = { | ||
component: MyComponent, | ||
tags: ['no-tests'], // 👈 Provides the `no-tests` tag to all stories in this file | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof MyComponent>; | ||
|
||
export const ExcludeStory: Story = { | ||
//👇 Adds the `no-tests` tag to this story to exclude it from the tests when enabled in the test-runner configuration | ||
tags: ['no-tests'], | ||
}; | ||
``` |
15 changes: 15 additions & 0 deletions
15
docs/snippets/common/my-component-include-tags.story.js.mdx
This file contains 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,15 @@ | ||
```js | ||
// MyComponent.stories.js|jsx | ||
|
||
import { MyComponent } from './MyComponent'; | ||
|
||
export default { | ||
component: MyComponent, | ||
tags: ['test-only'], // 👈 Provides the `test-only` tag to all stories in this file | ||
}; | ||
|
||
export const IncludeStory = { | ||
//👇 Adds the `test-only` tag to this story to be included in the tests when enabled in the test-runner configuration | ||
tags: ['test-only'], | ||
}; | ||
``` |
21 changes: 21 additions & 0 deletions
21
docs/snippets/common/my-component-include-tags.story.ts.mdx
This file contains 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,21 @@ | ||
```ts | ||
// MyComponent.stories.ts|tsx | ||
|
||
// Replace your-framework with the name of your framework | ||
import type { Meta, StoryObj } from '@storybook/your-framework'; | ||
|
||
import { MyComponent } from './MyComponent'; | ||
|
||
const meta: Meta<typeof MyComponent> = { | ||
component: MyComponent, | ||
tags: ['test-only'], // 👈 Provides the `test-only` tag to all stories in this file | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof MyComponent>; | ||
|
||
export const IncludeStory: Story = { | ||
//👇 Adds the `test-only` tag to this story to be included in the tests when enabled in the test-runner configuration | ||
tags: ['test-only'], | ||
}; | ||
``` |
This file contains 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,15 @@ | ||
```js | ||
// MyComponent.stories.js|jsx | ||
|
||
import { MyComponent } from './MyComponent'; | ||
|
||
export default { | ||
component: MyComponent, | ||
tags: ['skip-test'], // 👈 Provides the `skip-test` tag to all stories in this file | ||
}; | ||
|
||
export const SkipStory = { | ||
//👇 Adds the `skip-test` tag to this story to allow it to be skipped in the tests when enabled in the test-runner configuration | ||
tags: ['skip-test'], | ||
}; | ||
``` |
This file contains 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,21 @@ | ||
```ts | ||
// MyComponent.stories.ts|tsx | ||
|
||
// Replace your-framework with the name of your framework | ||
import type { Meta, StoryObj } from '@storybook/your-framework'; | ||
|
||
import { MyComponent } from './MyComponent'; | ||
|
||
const meta: Meta<typeof MyComponent> = { | ||
component: MyComponent, | ||
tags: ['skip-test'], // 👈 Provides the `skip-test` tag to all stories in this file | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof MyComponent>; | ||
|
||
export const SkipStory: Story = { | ||
//👇 Adds the `skip-test` tag to this story to allow it to be skipped in the tests when enabled in the test-runner configuration | ||
tags: ['skip-test'], | ||
}; | ||
``` |
This file contains 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 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 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 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 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 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 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,12 @@ | ||
```js | ||
// .storybook/test-runner.js | ||
|
||
module.exports = { | ||
getHttpHeaders: async (url) => { | ||
const token = url.includes('prod') ? 'XYZ' : 'ABC'; | ||
return { | ||
Authorization: `Bearer ${token}`, | ||
}; | ||
}, | ||
}; | ||
``` |
This file contains 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,16 @@ | ||
```ts | ||
// .storybook/test-runner.ts | ||
|
||
import type { TestRunnerConfig } from '@storybook/test-runner'; | ||
|
||
const config: TestRunnerConfig = { | ||
getHttpHeaders: async (url) => { | ||
const token = url.includes('prod') ? 'prod-token' : 'dev-token'; | ||
return { | ||
Authorization: `Bearer ${token}`, | ||
}; | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` |
32 changes: 32 additions & 0 deletions
32
docs/snippets/common/test-runner-custom-page-viewport.js.mdx
This file contains 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,32 @@ | ||
```js | ||
// .storybook/test-runner.js | ||
|
||
const { getStoryContext } = require('@storybook/test-runner'); | ||
const { MINIMAL_VIEWPORTS } = require('@storybook/addon-viewport'); | ||
|
||
const DEFAULT_VIEWPORT_SIZE = { width: 1280, height: 720 }; | ||
|
||
module.exports = { | ||
async preVisit(page, story) { | ||
// Accesses the story's parameters and retrieves the viewport used to render it | ||
const context = await getStoryContext(page, story); | ||
const viewportName = context.parameters?.viewport?.defaultViewport; | ||
const viewportParameter = MINIMAL_VIEWPORTS[viewportName]; | ||
|
||
if (viewportParameter) { | ||
const viewportSize = Object.entries(viewportParameter.styles).reduce( | ||
(acc, [screen, size]) => ({ | ||
...acc, | ||
// Converts the viewport size from percentages to numbers | ||
[screen]: parseInt(size), | ||
}), | ||
{} | ||
); | ||
// Configures the Playwright page to use the viewport size | ||
page.setViewportSize(viewportSize); | ||
} else { | ||
page.setViewportSize(DEFAULT_VIEWPORT_SIZE); | ||
} | ||
}, | ||
}; | ||
``` |
36 changes: 36 additions & 0 deletions
36
docs/snippets/common/test-runner-custom-page-viewport.ts.mdx
This file contains 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,36 @@ | ||
```ts | ||
// .storybook/test-runner.js | ||
|
||
import type { TestRunnerConfig } from '@storybook/test-runner'; | ||
import { getStoryContext } from '@storybook/test-runner'; | ||
|
||
const { MINIMAL_VIEWPORTS } = require('@storybook/addon-viewport'); | ||
|
||
const DEFAULT_VIEWPORT_SIZE = { width: 1280, height: 720 }; | ||
|
||
const config: TestRunnerConfig = { | ||
async preVisit(page, story) { | ||
// Accesses the story's parameters and retrieves the viewport used to render it | ||
const context = await getStoryContext(page, story); | ||
const viewportName = context.parameters?.viewport?.defaultViewport; | ||
const viewportParameter = MINIMAL_VIEWPORTS[viewportName]; | ||
|
||
if (viewportParameter) { | ||
const viewportSize = Object.entries(viewportParameter.styles).reduce( | ||
(acc, [screen, size]) => ({ | ||
...acc, | ||
// Converts the viewport size from percentages to numbers | ||
[screen]: parseInt(size), | ||
}), | ||
{} | ||
); | ||
// Configures the Playwright page to use the viewport size | ||
page.setViewportSize(viewportSize); | ||
} else { | ||
page.setViewportSize(DEFAULT_VIEWPORT_SIZE); | ||
} | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` |
This file contains 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 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 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 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 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,11 @@ | ||
```js | ||
// .storybook/test-runner.js | ||
|
||
module.exports = { | ||
tags: { | ||
include: ['test-only', 'pages'], | ||
exclude: ['no-tests', 'tokens'], | ||
skip: ['skip-test', 'layout'], | ||
}, | ||
}; | ||
``` |
This file contains 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,15 @@ | ||
```ts | ||
// .storybook/test-runner.ts | ||
|
||
import type { TestRunnerConfig } from '@storybook/test-runner'; | ||
|
||
const config: TestRunnerConfig = { | ||
tags: { | ||
include: ['test-only', 'pages'], | ||
exclude: ['no-tests', 'tokens'], | ||
skip: ['skip-test', 'layout'], | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` |
This file contains 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,9 @@ | ||
```js | ||
// .storybook/test-runner.js | ||
|
||
module.exports = { | ||
tags: { | ||
exclude: ['no-tests'], | ||
}, | ||
}; | ||
``` |
13 changes: 13 additions & 0 deletions
13
docs/snippets/common/test-runner-tags-exclude.config.ts.mdx
This file contains 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,13 @@ | ||
```ts | ||
// .storybook/test-runner.ts | ||
|
||
import type { TestRunnerConfig } from '@storybook/test-runner'; | ||
|
||
const config: TestRunnerConfig = { | ||
tags: { | ||
exclude: ['no-tests'], | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` |
This file contains 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,9 @@ | ||
```js | ||
// .storybook/test-runner.js | ||
|
||
module.exports = { | ||
tags: { | ||
include: ['test-only'], | ||
}, | ||
}; | ||
``` |
13 changes: 13 additions & 0 deletions
13
docs/snippets/common/test-runner-tags-include.config.ts.mdx
This file contains 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,13 @@ | ||
```ts | ||
// .storybook/test-runner.ts | ||
|
||
import type { TestRunnerConfig } from '@storybook/test-runner'; | ||
|
||
const config: TestRunnerConfig = { | ||
tags: { | ||
include: ['test-only'], | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` |
This file contains 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,9 @@ | ||
```js | ||
// .storybook/test-runner.js | ||
|
||
module.exports = { | ||
tags: { | ||
skip: ['skip-test'], | ||
}, | ||
}; | ||
``` |
This file contains 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,13 @@ | ||
```ts | ||
// .storybook/test-runner.ts | ||
|
||
import type { TestRunnerConfig } from '@storybook/test-runner'; | ||
|
||
const config: TestRunnerConfig = { | ||
tags: { | ||
skip: ['skip-test'], | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` |
This file contains 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,25 @@ | ||
```js | ||
// .storybook/test-runner.js | ||
|
||
const { waitForPageReady } = require('@storybook/test-runner'); | ||
const { toMatchImageSnapshot } = require('jest-image-snapshot'); | ||
|
||
const customSnapshotsDir = `${process.cwd()}/__snapshots__`; | ||
|
||
module.exports = { | ||
setup() { | ||
expect.extend({ toMatchImageSnapshot }); | ||
}, | ||
async postVisit(page, context) { | ||
// Awaits for the page to be loaded and available including assets (e.g., fonts) | ||
await waitForPageReady(page); | ||
|
||
// Generates a snapshot file based on the story identifier | ||
const image = await page.screenshot(); | ||
expect(image).toMatchImageSnapshot({ | ||
customSnapshotsDir, | ||
customSnapshotIdentifier: context.id, | ||
}); | ||
}, | ||
}; | ||
``` |
This file contains 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,29 @@ | ||
```ts | ||
// .storybook/test-runner.ts | ||
|
||
import type { TestRunnerConfig } from '@storybook/test-runner'; | ||
import { waitForPageReady } from '@storybook/test-runner'; | ||
|
||
import { toMatchImageSnapshot } from 'jest-image-snapshot'; | ||
|
||
const customSnapshotsDir = `${process.cwd()}/__snapshots__`; | ||
|
||
const config: TestRunnerConfig = { | ||
setup() { | ||
expect.extend({ toMatchImageSnapshot }); | ||
}, | ||
async postVisit(page, context) { | ||
// Awaits for the page to be loaded and available including assets (e.g., fonts) | ||
await waitForPageReady(page); | ||
|
||
// Generates a snapshot file based on the story identifier | ||
const image = await page.screenshot(); | ||
expect(image).toMatchImageSnapshot({ | ||
customSnapshotsDir, | ||
customSnapshotIdentifier: context.id, | ||
}); | ||
}, | ||
}; | ||
|
||
export default config; | ||
``` |
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.