-
-
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 #28768 from storybookjs/vitest-integration
Addon Vitest: Add experimental vitest integration
- Loading branch information
Showing
161 changed files
with
3,763 additions
and
985 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
.nx/cache | ||
.nx/cache | ||
.vite-inspect |
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,38 @@ | ||
import { beforeAll, vi, expect as vitestExpect } from 'vitest'; | ||
|
||
import { setProjectAnnotations } from '@storybook/react'; | ||
import { userEvent as storybookEvent, expect as storybookExpect } from '@storybook/test'; | ||
|
||
import * as coreAnnotations from '../addons/toolbars/template/stories/preview'; | ||
import * as componentAnnotations from '../core/template/stories/preview'; | ||
// register global components used in many stories | ||
import '../renderers/react/template/components'; | ||
import * as projectAnnotations from './preview'; | ||
|
||
vi.spyOn(console, 'warn').mockImplementation((...args) => console.log(...args)); | ||
|
||
const annotations = setProjectAnnotations([ | ||
// @ts-expect-error check type errors later | ||
projectAnnotations, | ||
// @ts-expect-error check type errors later | ||
componentAnnotations, | ||
coreAnnotations, | ||
{ | ||
// experiment with injecting Vitest's interactivity API over our userEvent while tests run in browser mode | ||
// https://vitest.dev/guide/browser/interactivity-api.html | ||
loaders: async (context) => { | ||
// eslint-disable-next-line no-underscore-dangle | ||
if (globalThis.__vitest_browser__) { | ||
const vitest = await import('@vitest/browser/context'); | ||
const { userEvent: browserEvent } = vitest; | ||
context.userEvent = browserEvent.setup(); | ||
context.expect = vitestExpect; | ||
} else { | ||
context.userEvent = storybookEvent.setup(); | ||
context.expect = storybookExpect; | ||
} | ||
}, | ||
}, | ||
]); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { defaultExclude, defineProject, mergeConfig } from 'vitest/config'; | ||
|
||
import Inspect from 'vite-plugin-inspect'; | ||
|
||
import { vitestCommonConfig } from '../vitest.workspace'; | ||
|
||
const extraPlugins: any[] = []; | ||
if (process.env.INSPECT === 'true') { | ||
// this plugin assists in inspecting the Storybook Vitest plugin's transformation and sourcemaps | ||
extraPlugins.push( | ||
Inspect({ | ||
outputDir: '../.vite-inspect', | ||
build: true, | ||
open: true, | ||
include: ['**/*.stories.*'], | ||
}) | ||
); | ||
} | ||
|
||
export default mergeConfig( | ||
vitestCommonConfig, | ||
defineProject({ | ||
plugins: [ | ||
import('@storybook/experimental-addon-vitest/plugin').then(({ storybookTest }) => | ||
storybookTest({ | ||
configDir: process.cwd(), | ||
}) | ||
), | ||
...extraPlugins, | ||
], | ||
test: { | ||
name: 'storybook-ui', | ||
include: [ | ||
// TODO: test all core and addon stories later | ||
// './core/**/components/**/*.{story,stories}.?(c|m)[jt]s?(x)', | ||
'../addons/interactions/src/**/*.{story,stories}.?(c|m)[jt]s?(x)', | ||
], | ||
exclude: [ | ||
...defaultExclude, | ||
'../node_modules/**', | ||
'**/__mockdata__/**', | ||
// expected to fail in Vitest because of fetching /iframe.html to cause ECONNREFUSED | ||
'**/Zoom.stories.tsx', | ||
], | ||
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
provider: 'playwright', | ||
headless: true, | ||
screenshotFailures: false, | ||
}, | ||
setupFiles: ['./storybook.setup.ts'], | ||
environment: 'happy-dom', | ||
}, | ||
}) | ||
); |
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.