diff --git a/code/addons/test/src/vitest-plugin/index.ts b/code/addons/test/src/vitest-plugin/index.ts index 5451931152e7..e73549ded6d9 100644 --- a/code/addons/test/src/vitest-plugin/index.ts +++ b/code/addons/test/src/vitest-plugin/index.ts @@ -127,7 +127,7 @@ export const storybookTest = async (options?: UserOptions): Promise => { .replace('', `${headHtmlSnippet ?? ''}`) .replace('', `${bodyHtmlSnippet ?? ''}`); }, - async config(inputConfig_DoNotMutate) { + async config(inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED) { // ! We're not mutating the input config, instead we're returning a new partial config // ! see https://vite.dev/guide/api-plugin.html#config try { @@ -155,8 +155,9 @@ export const storybookTest = async (options?: UserOptions): Promise => { setupFiles: [ join(packageDir, '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_DoNotMutate.test?.setupFiles === 'string' && - inputConfig_DoNotMutate.test?.setupFiles, + typeof inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test + ?.setupFiles === 'string' && + inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test?.setupFiles, ].filter(Boolean) as string[], ...(finalOptions.storybookScript @@ -181,7 +182,8 @@ export const storybookTest = async (options?: UserOptions): Promise => { .map((path) => convertPathToPattern(path)), // if the existing deps.inline is true, we keep it as-is, because it will inline everything - ...(inputConfig_DoNotMutate.test?.server?.deps?.inline !== true + ...(inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test?.server?.deps + ?.inline !== true ? { server: { deps: { @@ -192,7 +194,7 @@ export const storybookTest = async (options?: UserOptions): Promise => { : {}), browser: { - ...inputConfig_DoNotMutate.test?.browser, + ...inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test?.browser, commands: { getInitialGlobals: () => { const envConfig = JSON.parse(process.env.VITEST_STORYBOOK_CONFIG ?? '{}'); @@ -209,8 +211,9 @@ export const storybookTest = async (options?: UserOptions): Promise => { }, }, // if there is a test.browser config AND test.browser.screenshotFailures is not explicitly set, we set it to false - ...(inputConfig_DoNotMutate.test?.browser && - inputConfig_DoNotMutate.test.browser.screenshotFailures === undefined + ...(inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test?.browser && + inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test.browser + .screenshotFailures === undefined ? { screenshotFailures: false, } @@ -219,7 +222,11 @@ export const storybookTest = async (options?: UserOptions): Promise => { }, envPrefix: Array.from( - new Set([...(inputConfig_DoNotMutate.envPrefix || []), 'STORYBOOK_', 'VITE_']) + new Set([ + ...(inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.envPrefix || []), + 'STORYBOOK_', + 'VITE_', + ]) ), resolve: { @@ -258,8 +265,12 @@ export const storybookTest = async (options?: UserOptions): Promise => { ); // alert the user of problems - if (inputConfig_DoNotMutate.test.include?.length > 0) { - console.warn( + if ( + inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test.include?.length > 0 + ) { + // remove the user's existing include, because we're replacing it with our own heuristic based on main.ts#stories + inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test.include = []; + console.log( picocolors.yellow(dedent` Warning: Starting in Storybook 8.5.0-alpha.18, the "test.include" option in Vitest is discouraged in favor of just using the "stories" field in your Storybook configuration. diff --git a/test-storybooks/portable-stories-kitchen-sink/react/vitest.workspace.ts b/test-storybooks/portable-stories-kitchen-sink/react/vitest.workspace.ts index f1657f3acddd..041918fb126d 100644 --- a/test-storybooks/portable-stories-kitchen-sink/react/vitest.workspace.ts +++ b/test-storybooks/portable-stories-kitchen-sink/react/vitest.workspace.ts @@ -10,9 +10,6 @@ export default defineWorkspace([ test: { name: "storybook", pool: "threads", - include: [ - "stories/AddonTest.stories.?(c|m)[jt]s?(x)", - ], deps: { optimizer: { web: { @@ -30,4 +27,4 @@ export default defineWorkspace([ environment: "happy-dom", }, }, -]); \ No newline at end of file +]);