Skip to content

Addon-Vitest: Append Storybook project to existing test.projects array without double nesting#33708

Merged
valentinpalkovic merged 1 commit into
nextfrom
valentin/addon-vitest-prevent-double-nesting
Jan 29, 2026
Merged

Addon-Vitest: Append Storybook project to existing test.projects array without double nesting#33708
valentinpalkovic merged 1 commit into
nextfrom
valentin/addon-vitest-prevent-double-nesting

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented Jan 29, 2026

Closes #33706

What I did

When running the postinstall script for @storybook/addon-vitest, the migration logic could incorrectly wrap an existing Vitest config that already used a projects array inside a new project object. That produced an invalid double-nested structure (test.projects[0].test.projects) and broke Vitest.

Result: A config like:

test: {
  expect: { requireAssertions: true },
  projects: [
    { extends: "./vite.config.ts", test: { name: "client" } },
    { extends: "./vite.config.ts", test: { name: "server" } },
  ],
},

is now updated to add the storybook project as a third item in projects, instead of wrapping client/server in an extra project and breaking the structure.

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

  1. In a project that already has vitest.config.ts with test.projects (e.g. client + server), add/init @storybook/addon-vitest.
  2. Confirm vitest.config.ts is updated so the storybook project is a new entry in the existing projects array, not a wrapper around the previous config.
  3. Run npx vitest --project=storybook and ensure tests run.

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-33708-sha-df1d2018. Try it out in a new sandbox by running npx storybook@0.0.0-pr-33708-sha-df1d2018 sandbox or in an existing project with npx storybook@0.0.0-pr-33708-sha-df1d2018 upgrade.

More information
Published version 0.0.0-pr-33708-sha-df1d2018
Triggered by @valentinpalkovic
Repository storybookjs/storybook
Branch valentin/addon-vitest-prevent-double-nesting
Commit df1d2018
Datetime Thu Jan 29 10:44:53 UTC 2026 (1769683493)
Workflow run 21475119273

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 publish.yml --field pr=33708

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Vitest configuration merging to prevent double nesting when appending Storybook projects to existing multi-project arrays.
    • Enhanced multi-project configuration handling to properly preserve existing test settings while adding new projects.
  • Tests

    • Added test coverage for Storybook project configuration appending to existing multi-project arrays.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Introduces multi-project handling for Vitest configuration merging. A new helper detects existing test.projects arrays in target configs. When present, template project configurations are appended to the array. Additionally, a test case validates that storybook projects are appended to existing projects without duplication or nesting issues.

Changes

Cohort / File(s) Summary
Vitest Multi-Project Configuration
code/addons/vitest/src/updateVitestFile.ts, code/addons/vitest/src/updateVitestFile.test.ts
Implementation adds hasProjectsProp helper and conditional logic to append template projects to existing test.projects arrays, or restructure configs to single-project format when needed. Preserves coverage configuration at appropriate levels. Test case validates appending storybook projects to existing projects array without nesting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jan 29, 2026

View your CI Pipeline Execution ↗ for commit df1d201

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 9m 30s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-29 16:19:48 UTC

@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jan 29, 2026
@valentinpalkovic valentinpalkovic merged commit 5bbb915 into next Jan 29, 2026
136 of 146 checks passed
@valentinpalkovic valentinpalkovic deleted the valentin/addon-vitest-prevent-double-nesting branch January 29, 2026 16:09
@github-actions github-actions Bot mentioned this pull request Jan 30, 2026
10 tasks
valentinpalkovic added a commit that referenced this pull request Jan 30, 2026
…ent-double-nesting

Addon-Vitest: Append Storybook project to existing test.projects array without double nesting
(cherry picked from commit 5bbb915)
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jan 30, 2026
@github-actions github-actions Bot mentioned this pull request Jan 30, 2026
24 tasks
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 patch:yes Bugfix & documentation PR that need to be picked to main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Addon-vitest postinstall script incorrectly nests existing Vitest projects

2 participants