Skip to content

Addon Vitest: Support init in Vitest >= 3.2#31715

Merged
valentinpalkovic merged 14 commits into
nextfrom
valentin/support-vitest-3-2
Jun 16, 2025
Merged

Addon Vitest: Support init in Vitest >= 3.2#31715
valentinpalkovic merged 14 commits into
nextfrom
valentin/support-vitest-3-2

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented Jun 10, 2025

Closes #31689

What I did

  • Use the projects field when initializing Addon Vitest for Vitest 3.2 users
  • Added optimizeDeps to @storybook/addon-vitest
  • Fixed a bug where some preview annotations weren't added for Next.js
  • Refactored the vitest config override for our sandboxes so that we only apply small changes instead of overriding the whole config

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-31715-sha-b9a0ceb9. Try it out in a new sandbox by running npx storybook@0.0.0-pr-31715-sha-b9a0ceb9 sandbox or in an existing project with npx storybook@0.0.0-pr-31715-sha-b9a0ceb9 upgrade.

More information
Published version 0.0.0-pr-31715-sha-b9a0ceb9
Triggered by @valentinpalkovic
Repository storybookjs/storybook
Branch valentin/support-vitest-3-2
Commit b9a0ceb9
Datetime Fri Jun 13 14:07:41 UTC 2025 (1749823661)
Workflow run 15636541237

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=31715

Greptile Summary

Updates the Vitest addon to support Vitest >= 3.2 by using the projects field instead of the deprecated workspace file configuration.

  • Added new template vitest.config.3.2.template.ts utilizing the projects array instead of workspace config
  • Updated postinstall script to detect Vitest version and apply appropriate configuration template
  • Modified config file updater to handle both legacy workspace and new projects field formats
  • Updated dependencies to support Vitest ^3.2.0 while maintaining backward compatibility
  • Added comprehensive documentation explaining configuration differences between Vitest versions

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 10, 2025

View your CI Pipeline Execution ↗ for commit 29b367b.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 14s View ↗

☁️ Nx Cloud last updated this comment at 2025-06-16 12:44:25 UTC

@valentinpalkovic valentinpalkovic force-pushed the valentin/support-vitest-3-2 branch from 6cab441 to af7fb1b Compare June 13, 2025 09:50
@valentinpalkovic valentinpalkovic self-assigned this Jun 13, 2025
@valentinpalkovic valentinpalkovic changed the title WIP: Addon Vitest: Support init in Vitest >= 3.2 Addon Vitest: Support init in Vitest >= 3.2 Jun 13, 2025
@valentinpalkovic valentinpalkovic marked this pull request as ready for review June 13, 2025 10:52
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, 4 comments
Edit PR Review Bot Settings | Greptile

Comment on lines +16 to +17
// Use `workspace` field in Vitest < 3.2
projects: [{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Comment implies this field should be used for Vitest < 3.2, but it's actually for >= 3.2. Update comment to avoid confusion.

Comment on lines +59 to +60
// Use `workspace` field in Vitest < 3.2
projects: [{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Same incorrect comment about Vitest version compatibility in Vue template.

Comment on lines +102 to +103
// Use `workspace` field in Vitest < 3.2
projects: [{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Same incorrect comment about Vitest version compatibility in Svelte template.

Comment on lines 409 to +413
const hasWorkspaceConfig = configFile.includes('workspace:');
const hasProjectsConfig = configFile.includes('projects:');
const configFileHasTypeReference = configFile.match(
/\/\/\/\s*<reference\s+types=["']vitest\/config["']\s*\/>/
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: ensure both workspace: and projects: checks are using strict string matching (e.g., /\bworkspace:\b/.test(configFile)) to avoid false positives

@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented Jun 13, 2025

Package Benchmarks

Commit: 29b367b, ran on 16 June 2025 at 12:50:06 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 49 49 0
Self size 31.85 MB 31.87 MB 🚨 +16 KB 🚨
Dependency size 17.41 MB 17.41 MB 0 B
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 531 531 0
Self size 217 KB 902 KB 🚨 +686 KB 🚨
Dependency size 58.92 MB 58.92 MB 🚨 +172 B 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 131 131 0
Self size 2.39 MB 3.07 MB 🚨 +685 KB 🚨
Dependency size 22.30 MB 22.30 MB 🚨 +500 B 🚨
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 50 50 0
Self size 1 KB 1 KB 0 B
Dependency size 49.26 MB 49.27 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 216 216 0
Self size 582 KB 582 KB 0 B
Dependency size 94.58 MB 94.59 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 185 185 0
Self size 31 KB 31 KB 0 B
Dependency size 78.71 MB 78.72 MB 🚨 +16 KB 🚨
Bundle Size Analyzer Link Link

Comment thread code/builders/builder-vite/src/constants.ts Outdated

const extension = extname(rootConfig).includes('ts') ? '.ts' : '.js';
const newWorkspaceFile = resolve(dirname(rootConfig), `vitest.workspace${extension}`);
const workspaceTemplate = await loadTemplate('vitest.workspace.template.ts', {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the vitest.workspace.template.ts file be deleted then, or is it still being used somewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still used in the case the user has an existing workspace file.


<details id="example-vitest-workspace">
<summary>Example Vitest workspace file</summary>
<summary>Example Vitest workspace file (Vitest < 3.2)</summary>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think it makes more sense to remove this section altogether, now that the example config file already has everything, including pre and post Vitest 3.2?

And also adjust https://github.com/storybookjs/storybook/pull/31715/files#diff-64c8d1c5581a216a909dc8ece0c8611404e6add0ec5d6f9faecdec6ae300dbbeR66 to not mention a separate worksapce file.

cc @kylegach

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I wanted to do initially, but @yannbf vetoed and wanted to keep the documentation for people who already have a workspace configuration in place.

@valentinpalkovic valentinpalkovic merged commit 1cce824 into next Jun 16, 2025
56 of 57 checks passed
@valentinpalkovic valentinpalkovic deleted the valentin/support-vitest-3-2 branch June 16, 2025 12:58
@github-actions github-actions Bot mentioned this pull request Jun 16, 2025
71 tasks
@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jun 17, 2025
@github-actions github-actions Bot mentioned this pull request Jun 17, 2025
15 tasks
valentinpalkovic added a commit that referenced this pull request Jun 17, 2025
Addon Vitest: Support init in Vitest >= 3.2

(cherry picked from commit 1cce824)
@github-actions github-actions Bot mentioned this pull request Jun 18, 2025
15 tasks
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jun 18, 2025
@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addon: vitest bug ci:normal patch:done Patch/release PRs already cherry-picked to main/release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Vitest Addon using Deprecated Workspace File

3 participants