Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vitest: Add plugins from viteFinal #30105

Merged
merged 21 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4fdafc1
rename packageDir
JReinhold Dec 18, 2024
5110c71
don't enforce pre on the vitest plugin
JReinhold Dec 18, 2024
a079a28
selectively optimize modules to not let vite optimize everything (it …
JReinhold Dec 18, 2024
8bc928b
add plugins from viteFinal
JReinhold Dec 18, 2024
89036fe
don't exclude stories.svelte files from svelte sandboxes
JReinhold Dec 18, 2024
2259584
support undefined plugins array
JReinhold Dec 19, 2024
4bce136
remove vite plugins unnecessary for testing
JReinhold Dec 19, 2024
20f5254
also ignore @joshwooding/vite-plugin-react-docgen-typescript
JReinhold Dec 19, 2024
c38eed3
don't add plugins during postinstall
JReinhold Dec 19, 2024
470c04c
don't tell users to add framework plugins in docs
JReinhold Dec 19, 2024
21873f1
add migration note about removing duplicate vite configurations
JReinhold Dec 19, 2024
4512a5a
remove docs on manual Framework plugins
JReinhold Dec 19, 2024
a045f4e
don't add framework plugins to sandboxes
JReinhold Dec 19, 2024
5bb9a7f
fix react-vite and nextjs-vite viteFinals discarding configs from pre…
JReinhold Dec 20, 2024
e1cd01a
cleanup viteFinals
JReinhold Dec 20, 2024
2e1ad63
Merge branch 'next' into jeppe/support-svelte-csf-in-vitest
JReinhold Dec 20, 2024
5591ef4
Merge branch 'next' into jeppe/support-svelte-csf-in-vitest
JReinhold Dec 23, 2024
7c95fe0
Merge branch 'next' of github.com:storybookjs/storybook into jeppe/su…
JReinhold Jan 8, 2025
3c0886b
merge rnw preset changes
JReinhold Jan 8, 2025
a260929
Merge branch 'next' into jeppe/support-svelte-csf-in-vitest
JReinhold Jan 8, 2025
f7285f0
Merge branch 'next' of github.com:storybookjs/storybook into jeppe/su…
JReinhold Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions code/addons/test/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const getStoryGlobsAndFiles = async (
};
};

const packageDir = dirname(require.resolve('@storybook/experimental-addon-test/package.json'));
const PACKAGE_DIR = dirname(require.resolve('@storybook/experimental-addon-test/package.json'));

export const storybookTest = async (options?: UserOptions): Promise<Plugin> => {
export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> => {
const finalOptions = {
...defaultOptions,
...options,
Expand Down Expand Up @@ -109,14 +109,15 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin> => {
getStoryGlobsAndFiles(presets, directories),
presets.apply('framework', undefined),
presets.apply('env', {}),
presets.apply('viteFinal', {}),
presets.apply<{ plugins?: Plugin[] }>('viteFinal', {}),
JReinhold marked this conversation as resolved.
Show resolved Hide resolved
presets.apply('staticDirs', []),
extractTagsFromPreview(finalOptions.configDir),
]);

return {
const plugins = [...(viteConfigFromStorybook.plugins ?? [])];

plugins.push({
name: 'vite-plugin-storybook-test',
enforce: 'pre',
async transformIndexHtml(html) {
const [headHtmlSnippet, bodyHtmlSnippet] = await Promise.all([
presets.apply('previewHead'),
Expand Down Expand Up @@ -153,7 +154,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin> => {
const baseConfig: Omit<ViteUserConfig, 'plugins'> = {
test: {
setupFiles: [
join(packageDir, 'dist/vitest-plugin/setup-file.mjs'),
join(PACKAGE_DIR, 'dist/vitest-plugin/setup-file.mjs'),
// if the existing setupFiles is a string, we have to include it otherwise we're overwriting it
typeof inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test
?.setupFiles === 'string' &&
Expand All @@ -162,7 +163,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin> => {

...(finalOptions.storybookScript
? {
globalSetup: [join(packageDir, 'dist/vitest-plugin/global-setup.mjs')],
globalSetup: [join(PACKAGE_DIR, 'dist/vitest-plugin/global-setup.mjs')],
}
: {}),

Expand Down Expand Up @@ -244,7 +245,9 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin> => {

optimizeDeps: {
include: [
'@storybook/experimental-addon-test/**',
'@storybook/experimental-addon-test/internal/setup-file',
'@storybook/experimental-addon-test/internal/global-setup',
'@storybook/experimental-addon-test/internal/test-utils',
...(frameworkName?.includes('react') || frameworkName?.includes('nextjs')
? ['react-dom/test-utils']
: []),
Expand Down Expand Up @@ -317,7 +320,9 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin> => {
});
}
},
};
});

return plugins;
};

export default storybookTest;
1 change: 0 additions & 1 deletion scripts/tasks/sandbox-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
...defaultExclude,
// TODO: investigate TypeError: Cannot read properties of null (reading 'useContext')
"**/*argtypes*",
${template.expected.renderer === '@storybook/svelte' ? '"**/*.stories.svelte",' : ''}
],
/**
* TODO: Either fix or acknowledge limitation of:
Expand Down
Loading