forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
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 storybookjs#24645 from storybookjs/docs_test_runne…
…r_updates Docs: Test runner minor fixes
- Loading branch information
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; | ||
``` |
Oops, something went wrong.