Skip to content

Replace VITEST_STORYBOOK_CONFIG env var with typed module-level state; fix configOverride coverage detection#34514

Closed
Copilot wants to merge 2 commits intonextfrom
copilot/implement-vitest-configuration
Closed

Replace VITEST_STORYBOOK_CONFIG env var with typed module-level state; fix configOverride coverage detection#34514
Copilot wants to merge 2 commits intonextfrom
copilot/implement-vitest-configuration

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

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's configOverride.coverage was silently ignored when deciding whether to restart vitest with coverage enabled.

Changes

  • vitest-plugin/run-config.ts (new): typed module-level state with setCurrentRunConfig() / 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 indirection

  • node/test-manager.ts: replace process.env.VITEST_STORYBOOK_CONFIG = JSON.stringify(runConfig) with setCurrentRunConfig(runConfig)

  • vitest-plugin/index.ts: replace JSON.parse(process.env.VITEST_STORYBOOK_CONFIG ?? '{}') in the getInitialGlobals browser command with getCurrentRunConfig()

  • node/vitest-manager.ts: runTests() now derives effectiveConfig = runPayload.configOverride ?? config before computing coverageShouldBeEnabled, so a programmatic trigger with configOverride: { coverage: true } correctly restarts vitest with coverage on

// Before: coverage override via programmatic API was ignored
store.send({ type: 'TRIGGER_RUN', payload: { triggeredBy: 'external:ci', configOverride: { coverage: true, a11y: false } } });
// vitest was NOT restarted with coverage — runTests() read config.coverage from root store state

// After: effectiveConfig = configOverride ?? config
// vitest IS restarted with coverage enabled
  • node/test-manager.test.ts: two new tests covering configOverride-driven coverage restart and currentRun.config reflection
Original 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:

  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." - User seeks specific code related to test configuration.
  2. "tell me more about step 3. why is it an env var?" - User requests clarification on the use of environment variables.
  3. "okay this is great, we need to change this a bit..." - User outlines two goals for improving the vitest API: enabling custom configurations and ensuring all test reports are accessible.
  4. "Start implementation" - User indicates readiness to begin implementing the discussed changes.]

[Technical Inventory:

  • Technology: Vitest - a testing framework that the user is working with.
  • Configuration Management: The user is looking to enhance how configurations are passed to test runs, moving from environment variables to a direct API approach.
  • Reporting: The user wants to ensure all test reports are accessible through the triggering API.]

[Code Archaeology:

  • File: /Users/jeppe/dev/storybookjs/storybook/code/addons/vitest/src/preset.ts - This file is central to the user's requests regarding test configuration and reporting.
  • Recent Changes: The user is focused on modifying the logic for configuration handling and ensuring comprehensive reporting.]

[Progress Assessment:

  • Completed Tasks: User has identified the need for changes in the configuration and reporting logic.
  • Partially Complete Work: Implementation of the new configuration handling and reporting mechanisms is pending.]

[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:

  • Last Agent Commands: The user executed commands to summarize the conversation and initiate implementation.
  • Tool Results Summary: The summarization was triggered to encapsulate the conversation's progress and decisions made regarding the vitest API.
  • Pre-Summary State: The user was actively working on implementing changes to the vitest configuration and reporting mechanisms when the token budget was exceeded.
  • Operation Context: The commands were executed to clarify the conversation's direction and ensure all relevant information was documented for the next steps in the implementation process.]
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.
  1. Technical Foundation:
  • Vitest: A testing framework being utilized for managing test runs and configurations.
  1. 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.
  1. 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.

…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
Copilot AI requested a review from JReinhold April 9, 2026 20:06
@JReinhold JReinhold closed this Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants