Replace VITEST_STORYBOOK_CONFIG env var with typed module-level state; fix configOverride coverage detection#34514
Closed
Replace VITEST_STORYBOOK_CONFIG env var with typed module-level state; fix configOverride coverage detection#34514
Conversation
…ix configOverride coverage detection Agent-Logs-Url: https://github.com/storybookjs/storybook/sessions/0cb8f03d-c9aa-4239-be59-1ad99c36cae9 Co-authored-by: JReinhold <5678122+JReinhold@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Start implementation of vitest configuration enhancements
Replace VITEST_STORYBOOK_CONFIG env var with typed module-level state; fix configOverride coverage detection
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The vitest addon was passing run configuration (a11y, coverage) to the test environment via
process.env.VITEST_STORYBOOK_CONFIG(JSON-serialized), and the programmatic trigger API'sconfigOverride.coveragewas silently ignored when deciding whether to restart vitest with coverage enabled.Changes
vitest-plugin/run-config.ts(new): typed module-level state withsetCurrentRunConfig()/getCurrentRunConfig()— both the test manager and the vitest plugin run in the same child process, so they can share module state directly without env var indirectionnode/test-manager.ts: replaceprocess.env.VITEST_STORYBOOK_CONFIG = JSON.stringify(runConfig)withsetCurrentRunConfig(runConfig)vitest-plugin/index.ts: replaceJSON.parse(process.env.VITEST_STORYBOOK_CONFIG ?? '{}')in thegetInitialGlobalsbrowser command withgetCurrentRunConfig()node/vitest-manager.ts:runTests()now deriveseffectiveConfig = runPayload.configOverride ?? configbefore computingcoverageShouldBeEnabled, so a programmatic trigger withconfigOverride: { coverage: true }correctly restarts vitest with coverage onnode/test-manager.test.ts: two new tests coveringconfigOverride-driven coverage restart andcurrentRun.configreflectionOriginal prompt
Start implementation
The user has attached the following file paths as relevant context:
- AGENTS.md
- CLAUDE.md
[Chronological Review: The conversation began with the user requesting assistance in finding code related to configuration settings for test runs in the addon-vitest, specifically focusing on toggling coverage and accessibility (a11y) features. The user then sought clarification on why a certain configuration was set as an environment variable. Following this, the user outlined two primary goals aimed at enhancing the flexibility of the vitest triggering API, detailing the need for custom configurations and comprehensive test reports. The user concluded by initiating the implementation phase of these changes.][Intent Mapping:
[Technical Inventory:
[Code Archaeology:
[Progress Assessment:
[Context Validation: All necessary context for continuing work on the vitest API enhancements is captured, including user goals and specific implementation details.]
[Recent Commands Analysis:
1. Conversation Overview: - Primary Objectives: 1. "help me find the code in addon-vitest that sets configuration for test runs, eg. it toggles coverage and a11y, and passes that on to the test environment, via some env var." 2. "tell me more about step 3. why is it an env var?" 3. "okay this is great, we need to change this a bit..." - User outlines goals for flexible configurations and comprehensive reporting. 4. "Start implementation" - User indicates readiness to implement changes. - Session Context: The conversation flowed from identifying existing code to clarifying its functionality, followed by outlining new requirements and concluding with a readiness to implement. - User Intent Evolution: The user transitioned from seeking information to defining specific goals for enhancing the vitest API and finally to initiating implementation.- Technical Foundation:
- Vitest: A testing framework being utilized for managing test runs and configurations.
- Codebase Status:
- File Name: /Users/jeppe/dev/storybookjs/storybook/code/addons/vitest/src/preset.ts
- Purpose: Central to managing test configurations and reporting.
- Current State: User is preparing to implement changes for flexible configuration handling and comprehensive reporting.
- Key Code Segments: Focus on modifying how configurations are provided to the test environment.
- Dependencies: Changes will impact how tests are triggered and reported.
- Problem Resolution:
- Issues Encountered: Need for more flexible configuration handling and comprehensive reporting.
- Solutions Implemented: User has proposed using the vitest API directly for configuration instead of environment variables.
- Debugging Context: No specific debugging issues were mentioned, but the user is focused on implementing new features.
- Lessons Learned: The user...
Created from VS Code.