-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #28924 from storybookjs/docs-addon-vitest
Docs: Vitest plugin
- Loading branch information
Showing
18 changed files
with
802 additions
and
18 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
```shell renderer="common" language="js" packageManager="npx" | ||
npx storybook add @storybook/experimental-addon-test | ||
``` | ||
|
||
```shell renderer="common" language="js" packageManager="pnpm" | ||
pnpm exec storybook add @storybook/experimental-addon-test | ||
``` | ||
|
||
```shell renderer="common" language="js" packageManager="yarn" | ||
yarn exec storybook add @storybook/experimental-addon-test | ||
``` |
35 changes: 35 additions & 0 deletions
35
docs/_snippets/portable-stories-vitest-set-project-annotations-simple.md
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,35 @@ | ||
```tsx filename="setupTest.ts" renderer="react" language="ts" | ||
import { beforeAll } from 'vitest'; | ||
// 👇 If you're using Next.js, import from @storybook/nextjs | ||
// If you're using Next.js with Vite, import from @storybook/experimental-nextjs-vite | ||
import { setProjectAnnotations } from '@storybook/react'; | ||
import * as previewAnnotations from './.storybook/preview'; | ||
|
||
const annotations = setProjectAnnotations([previewAnnotations]); | ||
|
||
// Run Storybook's beforeAll hook | ||
beforeAll(annotations.beforeAll); | ||
``` | ||
|
||
```tsx filename="setupTest.ts" renderer="svelte" language="ts" | ||
import { beforeAll } from 'vitest'; | ||
// 👇 If you're using Sveltekit, import from @storybook/sveltekit | ||
import { setProjectAnnotations } from '@storybook/svelte'; | ||
import * as previewAnnotations from './.storybook/preview'; | ||
|
||
const annotations = setProjectAnnotations([previewAnnotations]); | ||
|
||
// Run Storybook's beforeAll hook | ||
beforeAll(annotations.beforeAll); | ||
``` | ||
|
||
```tsx filename="setupTest.ts" renderer="vue" language="ts" | ||
import { beforeAll } from 'vitest'; | ||
import { setProjectAnnotations } from '@storybook/vue3'; | ||
import * as previewAnnotations from './.storybook/preview'; | ||
|
||
const annotations = setProjectAnnotations([previewAnnotations]); | ||
|
||
// Run Storybook's beforeAll hook | ||
beforeAll(annotations.beforeAll); | ||
``` |
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 @@ | ||
```shell renderer="common" language="js" packageManager="npm" | ||
npm run test | ||
``` | ||
|
||
```shell renderer="common" language="js" packageManager="pnpm" | ||
pnpm run test | ||
``` | ||
|
||
```shell renderer="common" language="js" packageManager="yarn" | ||
yarn 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,29 @@ | ||
```js filename=".storybook/main.js" renderer="common" tabTitle="Before" | ||
import { mergeConfig } from 'vite'; | ||
|
||
export default { | ||
// ... | ||
viteFinal: async (viteConfig) => { | ||
return mergeConfig(viteConfig, { | ||
resolve: { | ||
alias: { | ||
'@components': '/src/components', | ||
// ... | ||
}, | ||
}, | ||
}); | ||
}, | ||
}; | ||
``` | ||
|
||
```js filename="vitest.config.ts" renderer="common" tabTitle="After" | ||
export default defineConfig({ | ||
// ... | ||
resolve: { | ||
alias: { | ||
'@components': '/src/components', | ||
// ... | ||
}, | ||
}, | ||
}); | ||
``` |
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,118 @@ | ||
```ts filename="vitest.config.ts" renderer="react" | ||
import { defineConfig, mergeConfig } from 'vitest/config'; | ||
import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin'; | ||
// 👇 If you're using Next.js, apply this framework plugin as well | ||
// import { storybookNextjsPlugin } from '@storybook/experimental-nextjs-vite/vite-plugin'; | ||
|
||
import viteConfig from './vite.config'; | ||
|
||
export default mergeConfig( | ||
viteConfig, | ||
defineConfig({ | ||
plugins: [ | ||
storybookTest({ | ||
// This should match your package.json script to run Storybook | ||
// The --ci flag will skip prompts and not open a browser | ||
storybookScript: 'yarn storybook --ci', | ||
}), | ||
// storybookNextjsPlugin(), | ||
], | ||
test: { | ||
// Glob pattern to find story files | ||
include: ['src/**/*.stories.?(m)[jt]s?(x)'], | ||
// Enable browser mode | ||
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
// Make sure to install Playwright | ||
provider: 'playwright', | ||
headless: true, | ||
}, | ||
// Speed up tests and better match how they run in Storybook itself | ||
// https://vitest.dev/config/#isolate | ||
// Consider removing this if you have flaky tests | ||
isolate: false, | ||
setupFiles: ['./.storybook/vitest.setup.ts'], | ||
}, | ||
}) | ||
); | ||
``` | ||
|
||
```ts filename="vitest.config.ts" renderer="vue" | ||
import { defineConfig, mergeConfig } from 'vitest/config'; | ||
import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin'; | ||
import { storybookVuePlugin } from '@storybook/vue3-vite/vite-plugin'; | ||
|
||
import viteConfig from './vite.config'; | ||
|
||
export default mergeConfig( | ||
viteConfig, | ||
defineConfig({ | ||
plugins: [ | ||
storybookTest({ | ||
// This should match your package.json script to run Storybook | ||
// The --ci flag will skip prompts and not open a browser | ||
storybookScript: 'yarn storybook --ci', | ||
}), | ||
storybookVuePlugin(), | ||
], | ||
test: { | ||
// Glob pattern to find story files | ||
include: ['src/**/*.stories.?(m)[jt]s?(x)'], | ||
// Enable browser mode | ||
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
// Make sure to install Playwright | ||
provider: 'playwright', | ||
headless: true, | ||
}, | ||
// Speed up tests and better match how they run in Storybook itself | ||
// https://vitest.dev/config/#isolate | ||
// Consider removing this if you have flaky tests | ||
isolate: false, | ||
setupFiles: ['./.storybook/vitest.setup.ts'], | ||
}, | ||
}) | ||
); | ||
``` | ||
|
||
```ts filename="vitest.config.ts" renderer="svelte" | ||
import { defineConfig, mergeConfig } from 'vitest/config'; | ||
import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin'; | ||
// 👇 If you're using Sveltekit, apply this framework plugin as well | ||
// import { storybookNextjsPlugin } from '@storybook/sveltekit/vite-plugin'; | ||
|
||
import viteConfig from './vite.config'; | ||
|
||
export default mergeConfig( | ||
viteConfig, | ||
defineConfig({ | ||
plugins: [ | ||
storybookTest({ | ||
// This should match your package.json script to run Storybook | ||
// The --ci flag will skip prompts and not open a browser | ||
storybookScript: 'yarn storybook --ci', | ||
}), | ||
// storybookSveltekitPlugin(), | ||
], | ||
test: { | ||
// Glob pattern to find story files | ||
include: ['src/**/*.stories.?(m)[jt]s?(x)'], | ||
// Enable browser mode | ||
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
// Make sure to install Playwright | ||
provider: 'playwright', | ||
headless: true, | ||
}, | ||
// Speed up tests and better match how they run in Storybook itself | ||
// https://vitest.dev/config/#isolate | ||
// Consider removing this if you have flaky tests | ||
isolate: false, | ||
setupFiles: ['./.storybook/vitest.setup.ts'], | ||
}, | ||
}) | ||
); | ||
``` |
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,128 @@ | ||
```ts title="vitest.workspace.ts" renderer="react" | ||
import { defineWorkspace } from 'vitest/config'; | ||
import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin'; | ||
// 👇 If you're using Next.js, apply this framework plugin as well | ||
// import { storybookNextjsPlugin } from '@storybook/experimental-nextjs-vite/vite-plugin'; | ||
|
||
export default defineWorkspace([ | ||
// This is the path to your existing Vitest config file | ||
'./vitest.config.ts', | ||
{ | ||
name: 'storybook', | ||
// This is the path to your existing Vite config file | ||
extends: './vite.config.ts', | ||
plugins: [ | ||
storybookTest({ | ||
// This should match your package.json script to run Storybook | ||
// The --ci flag will skip prompts and not open a browser | ||
storybookScript: 'yarn storybook --ci', | ||
}), | ||
// storybookNextjsPlugin(), | ||
], | ||
test: { | ||
// Glob pattern to find story files | ||
include: ['src/**/*.stories.?(m)[jt]s?(x)'], | ||
// Enable browser mode | ||
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
// Make sure to install Playwright | ||
provider: 'playwright', | ||
headless: true, | ||
}, | ||
// Speed up tests and better match how they run in Storybook itself | ||
// https://vitest.dev/config/#isolate | ||
// Consider removing this if you have flaky tests | ||
isolate: false, | ||
setupFiles: ['./.storybook/vitest.setup.ts'], | ||
}, | ||
}, | ||
]); | ||
``` | ||
|
||
```ts filename="vitest.config.ts" renderer="vue" | ||
import { defineConfig, mergeConfig } from 'vitest/config'; | ||
import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin'; | ||
import { storybookVuePlugin } from '@storybook/vue3-vite/vite-plugin'; | ||
|
||
import viteConfig from './vite.config'; | ||
|
||
export default defineWorkspace([ | ||
// This is the path to your existing Vitest config file | ||
'./vitest.config.ts', | ||
{ | ||
name: 'storybook', | ||
// This is the path to your existing Vite config file | ||
extends: './vite.config.ts', | ||
plugins: [ | ||
storybookTest({ | ||
// This should match your package.json script to run Storybook | ||
// The --ci flag will skip prompts and not open a browser | ||
storybookScript: 'yarn storybook --ci', | ||
}), | ||
storybookVuePlugin(), | ||
], | ||
test: { | ||
// Glob pattern to find story files | ||
include: ['src/**/*.stories.?(m)[jt]s?(x)'], | ||
// Enable browser mode | ||
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
// Make sure to install Playwright | ||
provider: 'playwright', | ||
headless: true, | ||
}, | ||
// Speed up tests and better match how they run in Storybook itself | ||
// https://vitest.dev/config/#isolate | ||
// Consider removing this if you have flaky tests | ||
isolate: false, | ||
setupFiles: ['./.storybook/vitest.setup.ts'], | ||
}, | ||
}, | ||
]); | ||
``` | ||
|
||
```ts filename="vitest.config.ts" renderer="svelte" | ||
import { defineConfig, mergeConfig } from 'vitest/config'; | ||
import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin'; | ||
// 👇 If you're using Sveltekit, apply this framework plugin as well | ||
// import { storybookNextjsPlugin } from '@storybook/sveltekit/vite-plugin'; | ||
|
||
import viteConfig from './vite.config'; | ||
|
||
export default defineWorkspace([ | ||
// This is the path to your existing Vitest config file | ||
'./vitest.config.ts', | ||
{ | ||
name: 'storybook', | ||
// This is the path to your existing Vite config file | ||
extends: './vite.config.ts', | ||
plugins: [ | ||
storybookTest({ | ||
// This should match your package.json script to run Storybook | ||
// The --ci flag will skip prompts and not open a browser | ||
storybookScript: 'yarn storybook --ci', | ||
}), | ||
// storybookSveltekitPlugin(), | ||
], | ||
test: { | ||
// Glob pattern to find story files | ||
include: ['src/**/*.stories.?(m)[jt]s?(x)'], | ||
// Enable browser mode | ||
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
// Make sure to install Playwright | ||
provider: 'playwright', | ||
headless: true, | ||
}, | ||
// Speed up tests and better match how they run in Storybook itself | ||
// https://vitest.dev/config/#isolate | ||
// Consider removing this if you have flaky tests | ||
isolate: false, | ||
setupFiles: ['./.storybook/vitest.setup.ts'], | ||
}, | ||
}, | ||
]); | ||
``` |
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
Oops, something went wrong.