Skip to content

Addon Vitest: Simplify setup file handling#35081

Closed
JReinhold wants to merge 1 commit into
nextfrom
jeppe/fix-vitest-project-config-setup-files
Closed

Addon Vitest: Simplify setup file handling#35081
JReinhold wants to merge 1 commit into
nextfrom
jeppe/fix-vitest-project-config-setup-files

Conversation

@JReinhold

@JReinhold JReinhold commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Closes #

What I did

This PR does two things in addon-vitest:

  1. Merge all handling of internal setup files to be done in configureVitest instead of being split between that and the config-hook. That split was causing a lot of unnecessary confusion.
  2. Change from setting context.vitest.setupFiles to context.project.setupFiles. Apparently the former would not have any effect.

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

Run Vitest CLI with a Storybook project, and trigger Vitest from the Storybook UI. I don't think it makes sense to do this from sandboxes, as they should already be doing this in CI.

Caution

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

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

  • 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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

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

Summary by CodeRabbit

  • Refactor
    • Reorganized internal Vitest plugin setup file initialization and handling logic.

@JReinhold JReinhold changed the title Vitest: Simplify setup file handling Addon Vitest: Simplify setup file handling Jun 6, 2026
@JReinhold JReinhold self-assigned this Jun 6, 2026
@JReinhold JReinhold added bug ci:normal Run our default set of CI jobs (choose this for most PRs). addon: vitest qa:needed Pull Requests that will need manual QA prior to release. labels Jun 6, 2026
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d6e2274-17ee-4d37-9712-47813b9d959e

📥 Commits

Reviewing files that changed from the base of the PR and between 78e4393 and e491d17.

📒 Files selected for processing (1)
  • code/addons/vitest/src/vitest-plugin/index.ts

📝 Walkthrough

Walkthrough

The Vitest plugin refactors setup-file injection by deferring the selection logic from the config() hook to the configureVitest() hook. The config() hook now only initializes base test expectations. The configureVitest() hook now conditionally selects internal setup files based on browser mode and project annotation requirements, then merges them with user-provided setup files while avoiding duplicates.

Changes

Vitest setup-file injection refactoring

Layer / File(s) Summary
Simplify config() hook initialization
code/addons/vitest/src/vitest-plugin/index.ts
In the config() hook, baseConfig.test initialization is simplified to only set expect configuration, removing the prior in-place construction of internal setupFiles there.
Move and expand setup-file logic to configureVitest() hook
code/addons/vitest/src/vitest-plugin/index.ts
In configureVitest(), internal setup-file selection and injection are moved and expanded: the plugin now computes internal setup file IDs based on browser mode and requiresProjectAnnotations, resolves them to file paths, and replaces projectConfig.setupFiles with internal setup files plus filtered user-provided setup files that exclude duplicates.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • storybookjs/storybook#33693: Both PRs modify the same Vitest plugin's config() hook to control baseConfig.test.expect.requireAssertions.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@JReinhold JReinhold closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addon: vitest bug ci:normal Run our default set of CI jobs (choose this for most PRs). qa:needed Pull Requests that will need manual QA prior to release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant