Skip to content

Commit bdea6d2

Browse files
authored
Merge pull request #28768 from storybookjs/vitest-integration
Addon Vitest: Add experimental vitest integration
2 parents 70e24c0 + 416cd00 commit bdea6d2

File tree

161 files changed

+3763
-985
lines changed

Some content is hidden

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

161 files changed

+3763
-985
lines changed

.circleci/config.yml

+45-13
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ jobs:
233233
name: Run tests
234234
command: |
235235
cd scripts
236-
yarn test --coverage --coverage.all=false
236+
yarn test --coverage
237237
- store_test_results:
238238
path: scripts/junit.xml
239239
- report-workflow-on-failure
240240
- cancel-workflow-on-failure
241241
unit-tests:
242242
executor:
243243
class: xlarge
244-
name: sb_node_22_browsers
244+
name: sb_playwright
245245
steps:
246246
- git-shallow-clone/checkout_advanced:
247247
clone_options: "--depth 1 --verbose"
@@ -251,7 +251,7 @@ jobs:
251251
name: Test
252252
command: |
253253
cd code
254-
yarn test --coverage --coverage.all=false
254+
yarn test --coverage
255255
- store_test_results:
256256
path: code/junit.xml
257257
- persist_to_workspace:
@@ -398,6 +398,26 @@ jobs:
398398
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task test-runner)
399399
- store_test_results:
400400
path: test-results
401+
vitest-integration:
402+
parameters:
403+
parallelism:
404+
type: integer
405+
executor:
406+
class: large
407+
name: sb_playwright
408+
parallelism: << parameters.parallelism >>
409+
steps:
410+
- git-shallow-clone/checkout_advanced:
411+
clone_options: "--depth 1 --verbose"
412+
- attach_workspace:
413+
at: .
414+
- run:
415+
name: Running story tests in Vitest
416+
command: yarn task --task vitest-integration --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task vitest-integration) --no-link --start-from=never --junit
417+
- report-workflow-on-failure:
418+
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task vitest-integration)
419+
- store_test_results:
420+
path: test-results
401421
test-runner-dev:
402422
parameters:
403423
parallelism:
@@ -679,29 +699,33 @@ workflows:
679699
requires:
680700
- unit-tests
681701
- create-sandboxes:
682-
parallelism: 13
702+
parallelism: 14
683703
requires:
684704
- build
685705
- build-sandboxes:
686-
parallelism: 13
706+
parallelism: 14
687707
requires:
688708
- create-sandboxes
689709
- chromatic-sandboxes:
690-
parallelism: 10
710+
parallelism: 11
691711
requires:
692712
- build-sandboxes
693713
- e2e-production:
694-
parallelism: 8
714+
parallelism: 9
695715
requires:
696716
- build-sandboxes
697717
- e2e-dev:
698718
parallelism: 2
699719
requires:
700720
- create-sandboxes
701721
- test-runner-production:
702-
parallelism: 8
722+
parallelism: 9
703723
requires:
704724
- build-sandboxes
725+
- vitest-integration:
726+
parallelism: 4
727+
requires:
728+
- create-sandboxes
705729
- bench:
706730
parallelism: 5
707731
requires:
@@ -741,29 +765,33 @@ workflows:
741765
requires:
742766
- unit-tests
743767
- create-sandboxes:
744-
parallelism: 19
768+
parallelism: 20
745769
requires:
746770
- build
747771
- build-sandboxes:
748-
parallelism: 19
772+
parallelism: 20
749773
requires:
750774
- create-sandboxes
751775
- chromatic-sandboxes:
752-
parallelism: 16
776+
parallelism: 17
753777
requires:
754778
- build-sandboxes
755779
- e2e-production:
756-
parallelism: 14
780+
parallelism: 15
757781
requires:
758782
- build-sandboxes
759783
- e2e-dev:
760784
parallelism: 2
761785
requires:
762786
- create-sandboxes
763787
- test-runner-production:
764-
parallelism: 14
788+
parallelism: 15
765789
requires:
766790
- build-sandboxes
791+
- vitest-integration:
792+
parallelism: 4
793+
requires:
794+
- create-sandboxes
767795
- test-portable-stories:
768796
requires:
769797
- build
@@ -827,6 +855,10 @@ workflows:
827855
parallelism: 33
828856
requires:
829857
- build-sandboxes
858+
- vitest-integration:
859+
parallelism: 8
860+
requires:
861+
- create-sandboxes
830862
- test-portable-stories:
831863
requires:
832864
- build

.github/workflows/tests-unit.yml

+4
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@ jobs:
2424

2525
- name: install and compile
2626
run: yarn task --task compile --start-from=auto
27+
28+
- name: Install Playwright Dependencies
29+
run: cd code && yarn exec playwright install chromium --with-deps
30+
2731
- name: test
2832
run: yarn test

MIGRATION.md

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h1>Migration</h1>
22

33
- [From version 8.2.x to 8.3.x](#from-version-82x-to-83x)
4+
- [Removed `experimental_SIDEBAR_BOTTOM` and deprecated `experimental_SIDEBAR_TOP` addon types](#removed-experimental_sidebar_bottom-and-deprecated-experimental_sidebar_top-addon-types)
45
- [New parameters format for addon backgrounds](#new-parameters-format-for-addon-backgrounds)
56
- [New parameters format for addon viewport](#new-parameters-format-for-addon-viewport)
67
- [From version 8.1.x to 8.2.x](#from-version-81x-to-82x)
@@ -104,17 +105,17 @@
104105
- [Tab addons cannot manually route, Tool addons can filter their visibility via tabId](#tab-addons-cannot-manually-route-tool-addons-can-filter-their-visibility-via-tabid)
105106
- [Removed `config` preset](#removed-config-preset-1)
106107
- [From version 7.5.0 to 7.6.0](#from-version-750-to-760)
107-
- [CommonJS with Vite is deprecated](#commonjs-with-vite-is-deprecated)
108-
- [Using implicit actions during rendering is deprecated](#using-implicit-actions-during-rendering-is-deprecated)
109-
- [typescript.skipBabel deprecated](#typescriptskipbabel-deprecated)
110-
- [Primary doc block accepts of prop](#primary-doc-block-accepts-of-prop)
111-
- [Addons no longer need a peer dependency on React](#addons-no-longer-need-a-peer-dependency-on-react)
108+
- [CommonJS with Vite is deprecated](#commonjs-with-vite-is-deprecated)
109+
- [Using implicit actions during rendering is deprecated](#using-implicit-actions-during-rendering-is-deprecated)
110+
- [typescript.skipBabel deprecated](#typescriptskipbabel-deprecated)
111+
- [Primary doc block accepts of prop](#primary-doc-block-accepts-of-prop)
112+
- [Addons no longer need a peer dependency on React](#addons-no-longer-need-a-peer-dependency-on-react)
112113
- [From version 7.4.0 to 7.5.0](#from-version-740-to-750)
113-
- [`storyStoreV6` and `storiesOf` is deprecated](#storystorev6-and-storiesof-is-deprecated)
114-
- [`storyIndexers` is replaced with `experimental_indexers`](#storyindexers-is-replaced-with-experimental_indexers)
114+
- [`storyStoreV6` and `storiesOf` is deprecated](#storystorev6-and-storiesof-is-deprecated)
115+
- [`storyIndexers` is replaced with `experimental_indexers`](#storyindexers-is-replaced-with-experimental_indexers)
115116
- [From version 7.0.0 to 7.2.0](#from-version-700-to-720)
116-
- [Addon API is more type-strict](#addon-api-is-more-type-strict)
117-
- [Addon-controls hideNoControlsWarning parameter is deprecated](#addon-controls-hidenocontrolswarning-parameter-is-deprecated)
117+
- [Addon API is more type-strict](#addon-api-is-more-type-strict)
118+
- [Addon-controls hideNoControlsWarning parameter is deprecated](#addon-controls-hidenocontrolswarning-parameter-is-deprecated)
118119
- [From version 6.5.x to 7.0.0](#from-version-65x-to-700)
119120
- [7.0 breaking changes](#70-breaking-changes)
120121
- [Dropped support for Node 15 and below](#dropped-support-for-node-15-and-below)
@@ -140,7 +141,7 @@
140141
- [Deploying build artifacts](#deploying-build-artifacts)
141142
- [Dropped support for file URLs](#dropped-support-for-file-urls)
142143
- [Serving with nginx](#serving-with-nginx)
143-
- [Ignore story files from node\_modules](#ignore-story-files-from-node_modules)
144+
- [Ignore story files from node_modules](#ignore-story-files-from-node_modules)
144145
- [7.0 Core changes](#70-core-changes)
145146
- [7.0 feature flags removed](#70-feature-flags-removed)
146147
- [Story context is prepared before for supporting fine grained updates](#story-context-is-prepared-before-for-supporting-fine-grained-updates)
@@ -154,7 +155,7 @@
154155
- [Addon-interactions: Interactions debugger is now default](#addon-interactions-interactions-debugger-is-now-default)
155156
- [7.0 Vite changes](#70-vite-changes)
156157
- [Vite builder uses Vite config automatically](#vite-builder-uses-vite-config-automatically)
157-
- [Vite cache moved to node\_modules/.cache/.vite-storybook](#vite-cache-moved-to-node_modulescachevite-storybook)
158+
- [Vite cache moved to node_modules/.cache/.vite-storybook](#vite-cache-moved-to-node_modulescachevite-storybook)
158159
- [7.0 Webpack changes](#70-webpack-changes)
159160
- [Webpack4 support discontinued](#webpack4-support-discontinued)
160161
- [Babel mode v7 exclusively](#babel-mode-v7-exclusively)
@@ -204,7 +205,7 @@
204205
- [Dropped addon-docs manual babel configuration](#dropped-addon-docs-manual-babel-configuration)
205206
- [Dropped addon-docs manual configuration](#dropped-addon-docs-manual-configuration)
206207
- [Autoplay in docs](#autoplay-in-docs)
207-
- [Removed STORYBOOK\_REACT\_CLASSES global](#removed-storybook_react_classes-global)
208+
- [Removed STORYBOOK_REACT_CLASSES global](#removed-storybook_react_classes-global)
208209
- [7.0 Deprecations and default changes](#70-deprecations-and-default-changes)
209210
- [storyStoreV7 enabled by default](#storystorev7-enabled-by-default)
210211
- [`Story` type deprecated](#story-type-deprecated)
@@ -419,6 +420,12 @@
419420

420421
## From version 8.2.x to 8.3.x
421422

423+
### Removed `experimental_SIDEBAR_BOTTOM` and deprecated `experimental_SIDEBAR_TOP` addon types
424+
425+
The experimental SIDEBAR_BOTTOM addon type was removed in favor of a built-in filter UI. The enum type definition will remain available until Storybook 9.0 but will be ignored. Similarly the experimental SIDEBAR_TOP addon type is deprecated and will be removed in a future version.
426+
427+
These APIs allowed addons to render arbitrary content in the Storybook sidebar. Due to potential conflicts between addons and challenges regarding styling, these APIs are/will be removed. In the future, Storybook will provide declarative API hooks to allow addons to add content to the sidebar without risk of conflicts or UI inconsistencies. One such API is `experimental_updateStatus` which allow addons to set a status for stories. The SIDEBAR_BOTTOM slot is now used to allow filtering stories with a given status.
428+
422429
### New parameters format for addon backgrounds
423430

424431
The `addon-backgrounds` addon now uses a new format for parameters. The `backgrounds` parameter is now an object with a `values` key that contains the background values.
@@ -448,7 +455,7 @@ Setting an override value should now be done via a `globals` property on your co
448455
export default {
449456
component: Button,
450457
globals: {
451-
backgrounds: { value: 'twitter' },
458+
backgrounds: { value: "twitter" },
452459
},
453460
};
454461
```
@@ -494,7 +501,7 @@ Setting an override value should now be done via a `globals` property on your co
494501
export default {
495502
component: Button,
496503
globals: {
497-
viewport: { value: 'phone' },
504+
viewport: { value: "phone" },
498505
},
499506
};
500507
```
@@ -2411,8 +2418,8 @@ export default config;
24112418

24122419
#### Vite builder uses Vite config automatically
24132420

2414-
When using a [Vite-based framework](#framework-field-mandatory), Storybook will automatically use your `vite.config.(ctm)js` config file starting in 7.0.
2415-
Some settings will be overridden by Storybook so that it can function properly, and the merged settings can be modified using `viteFinal` in `.storybook/main.js` (see the [Storybook Vite configuration docs](https://storybook.js.org/docs/react/builders/vite#configuration)).
2421+
When using a [Vite-based framework](#framework-field-mandatory), Storybook will automatically use your `vite.config.(ctm)js` config file starting in 7.0.
2422+
Some settings will be overridden by Storybook so that it can function properly, and the merged settings can be modified using `viteFinal` in `.storybook/main.js` (see the [Storybook Vite configuration docs](https://storybook.js.org/docs/react/builders/vite#configuration)).
24162423
If you were using `viteFinal` in 6.5 to simply merge in your project's standard Vite config, you can now remove it.
24172424

24182425
For Svelte projects this means that the `svelteOptions` property in the `main.js` config should be omitted, as it will be loaded automatically via the project's `vite.config.js`.

code/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.nx/cache
1+
.nx/cache
2+
.vite-inspect

code/.storybook/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const config: StorybookConfig = {
9494
'@storybook/addon-interactions',
9595
'@storybook/addon-storysource',
9696
'@storybook/addon-designs',
97+
'@storybook/experimental-addon-vitest',
9798
'@storybook/addon-a11y',
9899
'@chromatic-com/storybook',
99100
],

code/.storybook/preview.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { Fragment, useEffect } from 'react';
1+
import * as React from 'react';
2+
import { Fragment, useEffect } from 'react';
23

34
import type { Channel } from 'storybook/internal/channels';
45
import { DocsContext as DocsContextProps, useArgs } from 'storybook/internal/preview-api';
@@ -160,7 +161,7 @@ export const loaders = [
160161
}
161162
return { docsContext };
162163
},
163-
];
164+
] as Loader[];
164165

165166
export const decorators = [
166167
// This decorator adds the DocsContext created in the loader above

code/.storybook/storybook.setup.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { beforeAll, vi, expect as vitestExpect } from 'vitest';
2+
3+
import { setProjectAnnotations } from '@storybook/react';
4+
import { userEvent as storybookEvent, expect as storybookExpect } from '@storybook/test';
5+
6+
import * as coreAnnotations from '../addons/toolbars/template/stories/preview';
7+
import * as componentAnnotations from '../core/template/stories/preview';
8+
// register global components used in many stories
9+
import '../renderers/react/template/components';
10+
import * as projectAnnotations from './preview';
11+
12+
vi.spyOn(console, 'warn').mockImplementation((...args) => console.log(...args));
13+
14+
const annotations = setProjectAnnotations([
15+
// @ts-expect-error check type errors later
16+
projectAnnotations,
17+
// @ts-expect-error check type errors later
18+
componentAnnotations,
19+
coreAnnotations,
20+
{
21+
// experiment with injecting Vitest's interactivity API over our userEvent while tests run in browser mode
22+
// https://vitest.dev/guide/browser/interactivity-api.html
23+
loaders: async (context) => {
24+
// eslint-disable-next-line no-underscore-dangle
25+
if (globalThis.__vitest_browser__) {
26+
const vitest = await import('@vitest/browser/context');
27+
const { userEvent: browserEvent } = vitest;
28+
context.userEvent = browserEvent.setup();
29+
context.expect = vitestExpect;
30+
} else {
31+
context.userEvent = storybookEvent.setup();
32+
context.expect = storybookExpect;
33+
}
34+
},
35+
},
36+
]);
37+
38+
beforeAll(annotations.beforeAll);

code/.storybook/vitest.config.ts

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { defaultExclude, defineProject, mergeConfig } from 'vitest/config';
2+
3+
import Inspect from 'vite-plugin-inspect';
4+
5+
import { vitestCommonConfig } from '../vitest.workspace';
6+
7+
const extraPlugins: any[] = [];
8+
if (process.env.INSPECT === 'true') {
9+
// this plugin assists in inspecting the Storybook Vitest plugin's transformation and sourcemaps
10+
extraPlugins.push(
11+
Inspect({
12+
outputDir: '../.vite-inspect',
13+
build: true,
14+
open: true,
15+
include: ['**/*.stories.*'],
16+
})
17+
);
18+
}
19+
20+
export default mergeConfig(
21+
vitestCommonConfig,
22+
defineProject({
23+
plugins: [
24+
import('@storybook/experimental-addon-vitest/plugin').then(({ storybookTest }) =>
25+
storybookTest({
26+
configDir: process.cwd(),
27+
})
28+
),
29+
...extraPlugins,
30+
],
31+
test: {
32+
name: 'storybook-ui',
33+
include: [
34+
// TODO: test all core and addon stories later
35+
// './core/**/components/**/*.{story,stories}.?(c|m)[jt]s?(x)',
36+
'../addons/interactions/src/**/*.{story,stories}.?(c|m)[jt]s?(x)',
37+
],
38+
exclude: [
39+
...defaultExclude,
40+
'../node_modules/**',
41+
'**/__mockdata__/**',
42+
// expected to fail in Vitest because of fetching /iframe.html to cause ECONNREFUSED
43+
'**/Zoom.stories.tsx',
44+
],
45+
browser: {
46+
enabled: true,
47+
name: 'chromium',
48+
provider: 'playwright',
49+
headless: true,
50+
screenshotFailures: false,
51+
},
52+
setupFiles: ['./storybook.setup.ts'],
53+
environment: 'happy-dom',
54+
},
55+
})
56+
);

code/addons/a11y/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"devDependencies": {
6363
"@storybook/global": "^5.0.0",
64-
"@storybook/icons": "^1.2.5",
64+
"@storybook/icons": "^1.2.10",
6565
"@testing-library/react": "^14.0.0",
6666
"lodash": "^4.17.21",
6767
"react": "^18.2.0",

0 commit comments

Comments
 (0)