Skip to content

Addon Vitest: Add component info to task meta#33394

Merged
yannbf merged 1 commit into
yann/ghost-stories-researchfrom
yann/improved-vitest-meta
Dec 22, 2025
Merged

Addon Vitest: Add component info to task meta#33394
yannbf merged 1 commit into
yann/ghost-stories-researchfrom
yann/improved-vitest-meta

Conversation

@yannbf
Copy link
Copy Markdown
Member

@yannbf yannbf commented Dec 18, 2025

Closes #

What I did

This PR introduces two new properties in the Vitest task meta: componentPath and componentName.
They are quite useful for post-processing code e.g. to analyze a vitest test run and group test results, which could be coming from multiple story files but relating to the same component file:

Modal.stories.tsx -> imports from ./Modal
Modal.Topbar.stories.tsx -> imports from ./Modal
Modal.Backdrop.stories.tsx -> imports from ./Modal

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

  • Breaking Changes

    • Test helper API changed to accept a single options object (now accepts optional component path/name).
  • Improvements

    • Tests now propagate component identity metadata for richer reporting.
    • Runtime now supports generating and serving component manifests and an index JSON endpoint.
  • Tests

    • Test suites updated to the new object-style API and added coverage for component info extraction.
  • Chores

    • Multiple package version bumps and dependency updates.

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Dec 18, 2025

View your CI Pipeline Execution ↗ for commit e54f0de

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ✅ Succeeded 7m 56s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-22 10:24:27 UTC

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 18, 2025

📝 Walkthrough

Walkthrough

Refactors the vitest test helper to accept a single object parameter (adding optional componentPath and componentName) and updates the transformer/tests to emit object-style calls. Large surrounding changes migrate story-source handling to a StoryIndex-driven, promise-based generator, add manifests generation/serving, and adjust related builder, watcher, and type code.

Changes

Cohort / File(s) Summary
Vitest test helper
code/addons/vitest/src/vitest-plugin/test-utils.ts
testStory signature changed from positional args to a single destructured object; new optional componentPath? and componentName? params; _task.meta now stores these fields.
CSF transformer & tests (vitest)
code/core/src/csf-tools/vitest-plugin/transformer.ts, code/core/src/csf-tools/vitest-plugin/transformer.test.ts
Transformer now extracts componentPath/componentName and emits _testStory({ exportName, story, meta, skipTags, storyId, testName?, componentPath?, componentName? }); tests and snapshots updated and add "component info extraction" cases.
StoryIndex generator / dev-server wiring
code/core/src/core-server/presets/common-preset.ts, code/core/src/core-server/dev-server.ts, code/core/src/core-server/utils/StoryIndexGenerator.ts, code/core/src/core-server/utils/StoryIndexGenerator.test.ts, code/core/src/core-server/utils/getStoryIndexGenerator.ts
Introduces promise-based storyIndexGenerator (singleton) and storyIndexGeneratorPromise; StoryIndexGenerator.invalidate signature simplified, adds onInvalidated listener; dev-server and presets wired to the promise pattern; removed old getStoryIndexGenerator module.
Index JSON / watch changes
code/core/src/core-server/utils/index-json.ts, code/core/src/core-server/utils/index-json.test.ts, code/core/src/core-server/utils/watch-story-specifiers.ts, code/core/src/core-server/utils/watch-story-specifiers.test.ts
Renamed/rewired APIs: useStoriesJsonregisterIndexJsonRoute, extractStoriesJsonwriteIndexJson; function params now accept storyIndexGeneratorPromise; watchStorySpecifiers onInvalidate callback signature changed to (path, removed) and batching introduced; tests updated.
Manifests generation & routes
code/core/src/core-server/utils/manifests/manifests.ts, code/core/src/core-server/utils/manifests/manifests.test.ts, code/core/src/core-server/utils/manifests/render-components-manifest.ts, code/core/src/core-server/build-static.ts
Adds writeManifests and registerManifests; runtime manifest file writing and routes for /manifests/:name.json and /manifests/components.html; renamed render function to renderComponentsManifest; build-static switched to use writeManifests and promise wiring.
Builder-vite: import generation & plugin wiring
code/builders/builder-vite/src/codegen-importfn-script.ts, code/builders/builder-vite/src/codegen-importfn-script.test.ts, code/builders/builder-vite/src/list-stories.ts (removed), code/builders/builder-vite/src/plugins/code-generator-plugin.ts, code/builders/builder-vite/src/optimizeDeps.ts, code/builders/builder-vite/src/utils/unique-import-paths.ts, code/builders/builder-vite/src/virtual-file-names.ts
Reworked import-fn generation to accept a StoryIndex and produce dynamic import code; removed listStories; added getUniqueImportPaths; plugin now lazily awaits a StoryIndexGenerator promise, generalizes virtual file IDs and async load/configureServer.
Csf/index input and types
code/core/src/csf-tools/CsfFile.ts, code/core/src/csf-tools/CsfFile.test.ts, code/core/src/types/modules/indexer.ts, docs/api/main-config/main-config-indexers.mdx
IndexInput.importPath made optional (removed from emitted indexInputs); docs note importPath defaults; tests adjusted to omit importPath.
Renderer React manifests
code/renderers/react/src/componentManifest/generator.ts, code/renderers/react/src/componentManifest/generator.test.ts, code/renderers/react/src/preset.ts
Replaces componentManifestGenerator with manifests API, reorganizes manifest assembly (helpers, uniq/grouping), changes exported alias to experimental_manifests; tests updated for new shape.
API/types and public surface
code/core/src/types/modules/core-common.ts, code/core/src/core-server/utils/index-json.ts (types usage), code/core/src/core-server/utils/doTelemetry.ts
Adds Manifests type and storyIndexGenerator? config field; removes ComponentManifestGenerator export; various public functions now accept storyIndexGeneratorPromise.
Tests, small refactors & workspace
code/builders/builder-vite/src/vite-config.test.ts, code/core/src/manager/components/sidebar/CreateNewStoryFileModal.tsx, storybook.code-workspace, docs/*, tests under core and builder adjusted
Minor test/comment/workspace/docs updates and added tests for manifests and index route behaviors.
Package/version and dependency bumps
multiple package.json files (e.g., code/*, code/addons/*, code/renderers/*, scripts/package.json, code/lib/*)
Many packages bumped from 10.2.0-alpha.710.2.0-alpha.9; several update es-toolkit dependency version.
Miscellaneous scripts change
scripts/sandbox/generate.ts
Removed cleanup that deleted Yarn Berry directory (~/.yarn/berry) in sandbox generation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas to focus review on:
    • Correct propagation and optional handling of componentPath / componentName through transformer → test emitter → _task.meta (edge cases, null/undefined).
    • StoryIndexGenerator lifecycle and concurrency: singleton promise initialization, invalidate/onInvalidated behavior, and callers migrating to await the promise.
    • Manifests generation and register route: error handling, content-type headers, async presets.apply usage, and write-to-disk behavior for components.html.
    • Builder-vite plugin async configureServer/load changes and virtual module ID generalization—ensure HMR and module resolution still behave as intended.
    • Tests and snapshots that were updated to reflect new shapes (ensure coverage for Vite/Windows paths and all import specifier cases).
    • Type changes: optional importPath and new public types (Manifests, storyIndexGenerator field) and their downstream effects.

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
code/core/src/csf-tools/vitest-plugin/transformer.ts (1)

155-166: Consider handling ImportNamespaceSpecifier for completeness.

The current implementation extracts componentName from ImportSpecifier (named imports) and ImportDefaultSpecifier (default imports), but doesn't handle ImportNamespaceSpecifier (namespace imports like import * as Button from './Button').

While namespace imports might be rare in story files, consider whether this case should be supported for consistency.

🔎 Proposed enhancement to handle namespace imports
 let componentNameLiteral = null;
 if (
   parsed._componentImportSpecifier &&
   (t.isImportSpecifier(parsed._componentImportSpecifier) ||
-    t.isImportDefaultSpecifier(parsed._componentImportSpecifier))
+    t.isImportDefaultSpecifier(parsed._componentImportSpecifier) ||
+    t.isImportNamespaceSpecifier(parsed._componentImportSpecifier))
 ) {
   componentNameLiteral = t.stringLiteral(parsed._componentImportSpecifier.local.name);
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between badd420 and 98576ce.

📒 Files selected for processing (3)
  • code/addons/vitest/src/vitest-plugin/test-utils.ts (2 hunks)
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts (27 hunks)
  • code/core/src/csf-tools/vitest-plugin/transformer.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use ESLint and Prettier configurations that are enforced in the codebase

Files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode

Files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{ts,tsx,js,jsx,mjs}: Use server-side logger from 'storybook/internal/node-logger' for Node.js code
Use client-side logger from 'storybook/internal/client-logger' for browser code
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
code/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions that need to be tested from their modules

Files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
code/**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier with --write flag to format code before committing
Run ESLint with yarn lint:js:cmd to check for linting issues and fix errors before committing

Files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
**/*.{test,spec}.{ts,tsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{test,spec}.{ts,tsx}: Test files should follow the naming pattern *.test.ts, *.test.tsx, *.spec.ts, or *.spec.tsx
Follow the spy mocking rules defined in .cursor/rules/spy-mocking.mdc for consistent mocking patterns with Vitest

Files:

  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/spy-mocking.mdc)

**/*.test.{ts,tsx,js,jsx}: Use vi.mock() with the spy: true option for all package and file mocks in Vitest tests
Place all mocks at the top of the test file before any test cases
Use vi.mocked() to type and access the mocked functions in Vitest tests
Implement mock behaviors in beforeEach blocks in Vitest tests
Mock all required dependencies that the test subject uses
Each mock implementation should return a Promise for async functions in Vitest
Mock implementations should match the expected return type of the original function
Mock all required properties and methods that the test subject uses in Vitest tests
Avoid direct function mocking without vi.mocked() in Vitest tests
Avoid mock implementations outside of beforeEach blocks in Vitest tests
Avoid mocking without the spy: true option in Vitest tests
Avoid inline mock implementations within test cases in Vitest tests
Avoid mocking only a subset of required dependencies in Vitest tests
Mock at the highest level of abstraction needed in Vitest tests
Keep mock implementations simple and focused in Vitest tests
Use type-safe mocking with vi.mocked() in Vitest tests
Document complex mock behaviors in Vitest tests
Group related mocks together in Vitest tests

Files:

  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
code/**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{test,spec}.{ts,tsx,js,jsx}: Write meaningful unit tests that actually import and call the functions being tested
Mock external dependencies using vi.mock() for file system, loggers, and other external dependencies in tests
Aim for high test coverage of business logic (75%+ for statements/lines) using coverage reports

Files:

  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
🧠 Learnings (15)
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Document complex mock behaviors in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid mocking only a subset of required dependencies in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid inline mock implementations within test cases in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Keep mock implementations simple and focused in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Mock all required properties and methods that the test subject uses in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid mock implementations outside of `beforeEach` blocks in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Implement mock behaviors in `beforeEach` blocks in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Group related mocks together in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-05T09:38:47.712Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Select/Select.tsx:200-204
Timestamp: 2025-11-05T09:38:47.712Z
Learning: Repo: storybookjs/storybook — Guidance: Until Storybook 11 is released, do not suggest using React.useId anywhere (e.g., in code/core/src/components/components/Select/Select.tsx) to maintain compatibility with React 17 runtimes. Prefer advising: accept a caller-provided props.id and, if needed, generate a client-only fallback id to minimize SSR hydration issues — but avoid useId. Resume prompting for useId after Storybook 11.

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{test,spec}.{ts,tsx,js,jsx} : Write meaningful unit tests that actually import and call the functions being tested

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx} : Export functions that need to be tested from their modules

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:59.279Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-11-24T17:49:59.279Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Mock at the highest level of abstraction needed in Vitest tests

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-11-24T17:49:31.838Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .cursorrules:0-0
Timestamp: 2025-11-24T17:49:31.838Z
Learning: Applies to code/vitest.workspace.ts : Vitest configuration is centralized in `code/vitest.workspace.ts` for workspace setup

Applied to files:

  • code/addons/vitest/src/vitest-plugin/test-utils.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Follow existing patterns and conventions in the Storybook codebase

Applied to files:

  • code/addons/vitest/src/vitest-plugin/test-utils.ts
  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
📚 Learning: 2025-09-24T09:39:39.233Z
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32507
File: code/core/src/manager/globals/globals-module-info.ts:25-33
Timestamp: 2025-09-24T09:39:39.233Z
Learning: In Storybook, storybook/actions/decorator is a preview-only entrypoint and should not be included in manager globals configuration. The duplicatedKeys array in code/core/src/manager/globals/globals-module-info.ts is specifically for manager-side externalization, not preview entrypoints.

Applied to files:

  • code/core/src/csf-tools/vitest-plugin/transformer.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: normal
  • GitHub Check: nx
  • GitHub Check: Core Unit Tests, windows-latest
  • GitHub Check: get-branch
🔇 Additional comments (6)
code/core/src/csf-tools/vitest-plugin/transformer.ts (2)

242-262: LGTM! Clean object-based API transition.

The refactor from multiple positional arguments to a single object parameter improves maintainability and makes the API self-documenting. The conditional inclusion of componentPath and componentName is properly handled.


296-320: Consistent implementation across describe blocks.

The same object construction pattern is correctly applied in getDescribeStatementForStory, including the additional testName field for per-test metadata. This consistency is good for maintainability.

code/addons/vitest/src/vitest-plugin/test-utils.ts (2)

34-52: LGTM! Well-structured API refactor.

The migration to an object-based parameter makes the API more maintainable and easier to extend in the future. The optional fields componentPath, testName, and componentName are properly typed.


78-90: Proper metadata propagation.

The component identity fields are correctly extended in the task meta type and assigned to the task object, enabling downstream consumers to access component context information.

code/core/src/csf-tools/vitest-plugin/transformer.test.ts (2)

599-649: Good test coverage for component info extraction.

The new test suite covers the most common import patterns (named, default, and aliased imports). The tests verify that both componentPath and componentName are correctly extracted and included in the generated code.

If you decide to implement namespace import handling (as suggested in the transformer review), consider adding a corresponding test case:

it('should extract component name from namespace import specifier', async () => {
  const code = `
    import * as Button from './Button';
    export default {
      component: Button,
    }
    export const Primary = {};
  `;

  const result = await transform({ code });

  expect(result.code).toContain('componentPath: "./Button"');
  expect(result.code).toContain('componentName: "Button"');
});

76-82: Snapshot correctly reflects object-based API.

The updated snapshots consistently show the new object structure with named properties, making the test assertions clearer and the API more self-documenting.

@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented Dec 18, 2025

Package Benchmarks

Commit: e54f0de, ran on 22 December 2025 at 10:26:09 UTC

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

@storybook/addon-a11y

Before After Difference
Dependency count 0 2 🚨 +2 🚨
Self size 0 B 181 KB 🚨 +181 KB 🚨
Dependency size 0 B 2.97 MB 🚨 +2.97 MB 🚨
Bundle Size Analyzer Link Link

@storybook/addon-docs

Before After Difference
Dependency count 0 18 🚨 +18 🚨
Self size 0 B 1.64 MB 🚨 +1.64 MB 🚨
Dependency size 0 B 9.25 MB 🚨 +9.25 MB 🚨
Bundle Size Analyzer Link Link

@storybook/addon-links

Before After Difference
Dependency count 0 1 🚨 +1 🚨
Self size 0 B 14 KB 🚨 +14 KB 🚨
Dependency size 0 B 5 KB 🚨 +5 KB 🚨
Bundle Size Analyzer Link Link

@storybook/addon-onboarding

Before After Difference
Dependency count 0 0 0
Self size 0 B 331 KB 🚨 +331 KB 🚨
Dependency size 0 B 670 B 🚨 +670 B 🚨
Bundle Size Analyzer Link Link

storybook-addon-pseudo-states

Before After Difference
Dependency count 0 0 0
Self size 0 B 21 KB 🚨 +21 KB 🚨
Dependency size 0 B 689 B 🚨 +689 B 🚨
Bundle Size Analyzer Link Link

@storybook/addon-themes

Before After Difference
Dependency count 0 1 🚨 +1 🚨
Self size 0 B 18 KB 🚨 +18 KB 🚨
Dependency size 0 B 28 KB 🚨 +28 KB 🚨
Bundle Size Analyzer Link Link

@storybook/addon-vitest

Before After Difference
Dependency count 0 2 🚨 +2 🚨
Self size 0 B 377 KB 🚨 +377 KB 🚨
Dependency size 0 B 338 KB 🚨 +338 KB 🚨
Bundle Size Analyzer Link Link

@storybook/builder-vite

Before After Difference
Dependency count 0 17 🚨 +17 🚨
Self size 0 B 125 KB 🚨 +125 KB 🚨
Dependency size 0 B 2.00 MB 🚨 +2.00 MB 🚨
Bundle Size Analyzer Link Link

@storybook/builder-webpack5

Before After Difference
Dependency count 0 192 🚨 +192 🚨
Self size 0 B 75 KB 🚨 +75 KB 🚨
Dependency size 0 B 32.17 MB 🚨 +32.17 MB 🚨
Bundle Size Analyzer Link Link

storybook

Before After Difference
Dependency count 0 49 🚨 +49 🚨
Self size 0 B 19.92 MB 🚨 +19.92 MB 🚨
Dependency size 0 B 16.52 MB 🚨 +16.52 MB 🚨
Bundle Size Analyzer Link Link

@storybook/angular

Before After Difference
Dependency count 0 192 🚨 +192 🚨
Self size 0 B 118 KB 🚨 +118 KB 🚨
Dependency size 0 B 30.40 MB 🚨 +30.40 MB 🚨
Bundle Size Analyzer Link Link

@storybook/ember

Before After Difference
Dependency count 0 196 🚨 +196 🚨
Self size 0 B 15 KB 🚨 +15 KB 🚨
Dependency size 0 B 28.89 MB 🚨 +28.89 MB 🚨
Bundle Size Analyzer Link Link

@storybook/html-vite

Before After Difference
Dependency count 0 20 🚨 +20 🚨
Self size 0 B 22 KB 🚨 +22 KB 🚨
Dependency size 0 B 2.16 MB 🚨 +2.16 MB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 0 538 🚨 +538 🚨
Self size 0 B 646 KB 🚨 +646 KB 🚨
Dependency size 0 B 59.11 MB 🚨 +59.11 MB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 0 127 🚨 +127 🚨
Self size 0 B 1.12 MB 🚨 +1.12 MB 🚨
Dependency size 0 B 21.78 MB 🚨 +21.78 MB 🚨
Bundle Size Analyzer Link Link

@storybook/preact-vite

Before After Difference
Dependency count 0 20 🚨 +20 🚨
Self size 0 B 13 KB 🚨 +13 KB 🚨
Dependency size 0 B 2.15 MB 🚨 +2.15 MB 🚨
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 0 159 🚨 +159 🚨
Self size 0 B 30 KB 🚨 +30 KB 🚨
Dependency size 0 B 22.96 MB 🚨 +22.96 MB 🚨
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 0 117 🚨 +117 🚨
Self size 0 B 35 KB 🚨 +35 KB 🚨
Dependency size 0 B 19.58 MB 🚨 +19.58 MB 🚨
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 0 278 🚨 +278 🚨
Self size 0 B 24 KB 🚨 +24 KB 🚨
Dependency size 0 B 44.06 MB 🚨 +44.06 MB 🚨
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 0 204 🚨 +204 🚨
Self size 0 B 16 KB 🚨 +16 KB 🚨
Dependency size 0 B 33.43 MB 🚨 +33.43 MB 🚨
Bundle Size Analyzer Link Link

@storybook/svelte-vite

Before After Difference
Dependency count 0 24 🚨 +24 🚨
Self size 0 B 55 KB 🚨 +55 KB 🚨
Dependency size 0 B 26.82 MB 🚨 +26.82 MB 🚨
Bundle Size Analyzer Link Link

@storybook/sveltekit

Before After Difference
Dependency count 0 25 🚨 +25 🚨
Self size 0 B 56 KB 🚨 +56 KB 🚨
Dependency size 0 B 26.88 MB 🚨 +26.88 MB 🚨
Bundle Size Analyzer Link Link

@storybook/vue3-vite

Before After Difference
Dependency count 0 114 🚨 +114 🚨
Self size 0 B 35 KB 🚨 +35 KB 🚨
Dependency size 0 B 43.98 MB 🚨 +43.98 MB 🚨
Bundle Size Analyzer Link Link

@storybook/web-components-vite

Before After Difference
Dependency count 0 21 🚨 +21 🚨
Self size 0 B 19 KB 🚨 +19 KB 🚨
Dependency size 0 B 2.19 MB 🚨 +2.19 MB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 0 183 🚨 +183 🚨
Self size 0 B 775 KB 🚨 +775 KB 🚨
Dependency size 0 B 66.97 MB 🚨 +66.97 MB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 0 176 🚨 +176 🚨
Self size 0 B 30 KB 🚨 +30 KB 🚨
Dependency size 0 B 65.55 MB 🚨 +65.55 MB 🚨
Bundle Size Analyzer Link Link

@storybook/core-webpack

Before After Difference
Dependency count 0 1 🚨 +1 🚨
Self size 0 B 11 KB 🚨 +11 KB 🚨
Dependency size 0 B 28 KB 🚨 +28 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 0 50 🚨 +50 🚨
Self size 0 B 999 KB 🚨 +999 KB 🚨
Dependency size 0 B 36.44 MB 🚨 +36.44 MB 🚨
Bundle Size Analyzer node node

@storybook/csf-plugin

Before After Difference
Dependency count 0 9 🚨 +9 🚨
Self size 0 B 7 KB 🚨 +7 KB 🚨
Dependency size 0 B 1.26 MB 🚨 +1.26 MB 🚨
Bundle Size Analyzer Link Link

eslint-plugin-storybook

Before After Difference
Dependency count 0 20 🚨 +20 🚨
Self size 0 B 131 KB 🚨 +131 KB 🚨
Dependency size 0 B 2.81 MB 🚨 +2.81 MB 🚨
Bundle Size Analyzer Link Link

@storybook/react-dom-shim

Before After Difference
Dependency count 0 0 0
Self size 0 B 18 KB 🚨 +18 KB 🚨
Dependency size 0 B 788 B 🚨 +788 B 🚨
Bundle Size Analyzer Link Link

@storybook/preset-create-react-app

Before After Difference
Dependency count 0 68 🚨 +68 🚨
Self size 0 B 32 KB 🚨 +32 KB 🚨
Dependency size 0 B 5.98 MB 🚨 +5.98 MB 🚨
Bundle Size Analyzer Link Link

@storybook/preset-react-webpack

Before After Difference
Dependency count 0 170 🚨 +170 🚨
Self size 0 B 18 KB 🚨 +18 KB 🚨
Dependency size 0 B 31.20 MB 🚨 +31.20 MB 🚨
Bundle Size Analyzer Link Link

@storybook/preset-server-webpack

Before After Difference
Dependency count 0 10 🚨 +10 🚨
Self size 0 B 7 KB 🚨 +7 KB 🚨
Dependency size 0 B 1.20 MB 🚨 +1.20 MB 🚨
Bundle Size Analyzer Link Link

@storybook/html

Before After Difference
Dependency count 0 2 🚨 +2 🚨
Self size 0 B 29 KB 🚨 +29 KB 🚨
Dependency size 0 B 32 KB 🚨 +32 KB 🚨
Bundle Size Analyzer Link Link

@storybook/preact

Before After Difference
Dependency count 0 2 🚨 +2 🚨
Self size 0 B 16 KB 🚨 +16 KB 🚨
Dependency size 0 B 32 KB 🚨 +32 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react

Before After Difference
Dependency count 0 57 🚨 +57 🚨
Self size 0 B 717 KB 🚨 +717 KB 🚨
Dependency size 0 B 12.92 MB 🚨 +12.92 MB 🚨
Bundle Size Analyzer Link Link

@storybook/server

Before After Difference
Dependency count 0 3 🚨 +3 🚨
Self size 0 B 8 KB 🚨 +8 KB 🚨
Dependency size 0 B 716 KB 🚨 +716 KB 🚨
Bundle Size Analyzer Link Link

@storybook/svelte

Before After Difference
Dependency count 0 2 🚨 +2 🚨
Self size 0 B 45 KB 🚨 +45 KB 🚨
Dependency size 0 B 230 KB 🚨 +230 KB 🚨
Bundle Size Analyzer Link Link

@storybook/vue3

Before After Difference
Dependency count 0 3 🚨 +3 🚨
Self size 0 B 55 KB 🚨 +55 KB 🚨
Dependency size 0 B 211 KB 🚨 +211 KB 🚨
Bundle Size Analyzer Link Link

@storybook/web-components

Before After Difference
Dependency count 0 3 🚨 +3 🚨
Self size 0 B 41 KB 🚨 +41 KB 🚨
Dependency size 0 B 47 KB 🚨 +47 KB 🚨
Bundle Size Analyzer Link Link

Copy link
Copy Markdown
Member

@kasperpeulen kasperpeulen left a comment

Choose a reason for hiding this comment

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

LGTM

@yannbf yannbf force-pushed the yann/improved-vitest-meta branch from 98576ce to e54f0de Compare December 22, 2025 10:14
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (11)
code/lib/react-dom-shim/package.json (1)

51-51: Invalid character in gitHead hash.

The gitHead value ends with "1l" (one followed by lowercase L), but Git commit hashes must be hexadecimal (0-9, a-f only). The character "l" is invalid. This appears to be a typo—possibly "11" was mistyped as "1l".

While this won't break builds, it represents incorrect metadata.

code/lib/cli-storybook/package.json (1)

67-67: Invalid character in gitHead hash.

The gitHead value ends with 1l, but lowercase 'l' is not a valid hexadecimal character. Git commit hashes should only contain 0-9 and a-f. This appears to be a typo and should be corrected to avoid potential publishing issues.

code/lib/csf-plugin/package.json (1)

69-69: Invalid git commit hash in gitHead field.

The gitHead value ends with "1l" (one followed by lowercase L), but git commit hashes are hexadecimal strings that can only contain characters 0-9 and a-f. The letter 'l' is not a valid hexadecimal character. This could break tooling that validates or parses this field during publishing or version tracking.

Please correct this to use a valid git commit hash.

🔎 How to fix

Replace the invalid hash with the correct git commit hash:

-  "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae1l"
+  "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae10"

Or verify and use the actual current commit hash:

#!/bin/bash
# Get the current git commit hash
git rev-parse HEAD
code/presets/react-webpack/package.json (1)

69-69: Invalid Git SHA in gitHead field.

The gitHead value contains an invalid character. Git commit SHAs must be exactly 40 hexadecimal characters (0-9, a-f), but this value is 41 characters long and ends with 'l' (lowercase L), which is not a valid hex digit. This could cause package publishing failures or break version tracking tools.

🔎 Expected format

The gitHead should be a valid 40-character git commit SHA, for example:

-  "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae1l"
+  "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae10"

Or verify the correct commit SHA for this release:

#!/bin/bash
# Get the current HEAD commit SHA
git rev-parse HEAD
code/lib/core-webpack/package.json (1)

52-52: Invalid git commit hash in gitHead field.

The gitHead value ends with "1l", but git commit hashes are hexadecimal and can only contain characters 0-9 and a-f. The "l" character is invalid and appears to be a typo.

🔎 Suggested fix
-  "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae1l"
+  "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae11"

Note: If this field is auto-generated during publishing, it will likely be corrected automatically. However, it should be fixed in the source to avoid potential tooling issues.

code/frameworks/react-vite/package.json (1)

76-76: Invalid character in gitHead field.

The gitHead value ends with "1l" (one followed by lowercase L). Git commit hashes are hexadecimal and only contain characters 0-9 and a-f. The lowercase 'l' is not a valid hex digit. This should be corrected to a valid git commit hash.

🔎 Verification script
#!/bin/bash
# Description: Check if gitHead is a valid git commit hash

# Extract the gitHead value
git_head="a8e7fd8a655c69780bc20b9749d2699e45beae1l"

# Check if it's a valid hex string (should only contain 0-9, a-f)
if echo "$git_head" | grep -qE '^[0-9a-f]{40}$'; then
  echo "✓ Valid git commit hash"
else
  echo "✗ Invalid git commit hash: contains non-hex characters"
  echo "Hash: $git_head"
  echo "Last 5 chars: ${git_head: -5}"
fi

# Try to verify if this commit exists in the repository
if git cat-file -t "$git_head" 2>/dev/null; then
  echo "✓ Commit exists in repository"
else
  echo "✗ Commit does not exist in repository"
fi
code/lib/eslint-plugin/package.json (1)

70-70: Invalid character in gitHead hash.

The gitHead value ends with "l", which is not a valid hexadecimal character for a git commit hash. Git SHA-1 hashes only contain characters 0-9 and a-f.

This appears to be a typo—possibly the trailing character should be "1" instead of "l", or the hash may need regeneration.

🔎 Verify and correct the git commit hash

If this is meant to reference a real commit, verify the correct hash with:

#!/bin/bash
# Check recent commits to find the correct hash
git log --oneline -20 --format="%H %s"

The hash should be exactly 40 hexadecimal characters (0-9, a-f).

code/builders/builder-webpack5/package.json (1)

91-91: Fix invalid gitHead hash format.

The gitHead value ends with an invalid character 'l' (lowercase L). Git commit hashes must contain only hexadecimal characters (0-9 and a-f). Verify and correct this hash to a valid 40-character commit hash.

code/frameworks/preact-vite/package.json (1)

65-65: Fix the gitHead field — it contains an invalid hexadecimal character.

The gitHead value "a8e7fd8a655c69780bc20b9749d2699e45beae1l" is 41 characters long and ends with 'l', but git commit SHAs must be exactly 40 hexadecimal characters (0-9, a-f only). The trailing 'l' is not a valid hex digit and indicates a typo or corruption. Correct this before publishing.

code/presets/create-react-app/package.json (1)

53-53: Fix the invalid gitHead value.

The gitHead field contains an invalid git SHA: "a8e7fd8a655c69780bc20b9749d2699e45beae1l". Git commit hashes are 40-character hexadecimal strings (0-9 and a-f), but this value has 41 characters and ends with "1l" (digit one followed by lowercase letter 'l'). The character 'l' is not valid hexadecimal.

This field is populated by npm publish to point to the git HEAD SHA-1 at publish time. While gitHead is normally added automatically by npm and is useful to map packages back to a revision in the git repository, the invalid placeholder should be corrected or removed before publishing.

code/core/src/core-server/utils/manifests/render-components-manifest.ts (1)

712-712: Unused expression result.

The esc(c.error?.message || 'Unknown error') call result is not assigned or used. This appears to be dead code, possibly left over from a refactor.

🔎 Proposed fix
-  esc(c.error?.message || 'Unknown error');
   return `
🧹 Nitpick comments (14)
storybook.code-workspace (1)

11-13: Consider more targeted file association for JSX files.

Mapping all *.js files to javascriptreact may affect non-React JavaScript files (config files, build scripts, Node.js utilities). If the project contains JavaScript files without JSX, consider:

  • Using *.jsx extension for React component files, or
  • Accepting this trade-off if the vast majority of .js files contain JSX
Alternative approach if JSX files can be renamed

If feasible, remove the broad association and use the .jsx extension for React components:

-    "files.associations": {
-      "*.js": "javascriptreact",
-    },

This provides more accurate language support for each file type.

code/builders/builder-vite/src/codegen-importfn-script.test.ts (1)

18-20: Missing spy: true option on mocks.

Per coding guidelines, vi.mock() should include the spy: true option for consistent mocking patterns. The es-toolkit/function mock correctly uses { spy: true }, but watchpack and storybook/internal/node-logger do not.

🔎 Proposed fix
-vi.mock('watchpack');
+vi.mock('watchpack', { spy: true });
 vi.mock('es-toolkit/function', { spy: true });
-vi.mock('storybook/internal/node-logger');
+vi.mock('storybook/internal/node-logger', { spy: true });

Based on coding guidelines for Vitest tests.

code/core/src/core-server/utils/manifests/render-components-manifest.ts (1)

862-864: Duplicate comment.

The comment "// Prefer raw if provided" appears twice on consecutive lines.

🔎 Proposed fix
   // Prefer raw if provided
-  // Prefer raw if provided
   if ('raw' in tsType && typeof tsType.raw === 'string' && tsType.raw.trim().length > 0) {
code/core/src/core-server/utils/doTelemetry.ts (1)

19-22: Redundant optional chaining.

Since storyIndexGeneratorPromise now resolves to StoryIndexGenerator (not StoryIndexGenerator | undefined), the optional chaining on generator?.getIndexAndStats() is unnecessary.

🔎 Proposed fix
     const generator = await storyIndexGeneratorPromise;
     let indexAndStats;
     try {
-      indexAndStats = await generator?.getIndexAndStats();
+      indexAndStats = await generator.getIndexAndStats();
     } catch (err) {
code/core/src/core-server/utils/index-json.test.ts (1)

18-20: Missing spy: true option on some mocks.

For consistency with the coding guidelines and the es-toolkit/function mock, add spy: true to the other mocks.

🔎 Proposed fix
-vi.mock('watchpack');
+vi.mock('watchpack', { spy: true });
 vi.mock('es-toolkit/function', { spy: true });
-vi.mock('storybook/internal/node-logger');
+vi.mock('storybook/internal/node-logger', { spy: true });

Based on coding guidelines for Vitest tests.

code/core/src/core-server/dev-server.ts (1)

172-173: Potentially redundant optional chaining.

Since storyIndexGeneratorPromise resolves to StoryIndexGenerator (per the type at line 47), the optional chaining on generator?.getIndexAndStats() may be unnecessary. However, within a catch block for telemetry, defensive coding is reasonable.

🔎 Proposed fix (if strict typing is desired)
       const generator = await storyIndexGeneratorPromise;
-      const indexAndStats = await generator?.getIndexAndStats();
+      const indexAndStats = await generator.getIndexAndStats();
code/renderers/react/src/componentManifest/generator.ts (1)

53-85: Good per-story error isolation in extractStories.

The try/catch around individual story extraction ensures one failing story doesn't prevent others from being processed. The error objects include both name and message for debugging.

Minor note: The invariant(e instanceof Error) on line 78 will throw if a non-Error value is caught. While rare, this could mask the original error. Consider using a safer pattern:

🔎 Suggested defensive handling
      } catch (e) {
-       invariant(e instanceof Error);
+       const error = e instanceof Error ? e : new Error(String(e));
        return {
          name: storyName,
-         error: { name: e.name, message: e.message },
+         error: { name: error.name, message: error.message },
        };
      }
code/core/src/core-server/utils/manifests/manifests.ts (1)

49-65: Consider setting Content-Type for 404 responses on the JSON route.

The JSON route correctly sets Content-Type: application/json for success responses but omits it for 404 responses. For consistency with the HTML route (which sets Content-Type for 404), consider adding the header:

🔎 Suggested improvement
      } else {
        res.statusCode = 404;
+       res.setHeader('Content-Type', 'text/plain; charset=utf-8');
        res.end(`Manifest "${req.params.name}" not found`);
      }
code/core/src/core-server/utils/StoryIndexGenerator.ts (1)

798-807: Consider defensive error handling for listener notifications.

The listener notification loop at line 806 will propagate exceptions from any listener, potentially leaving other listeners unnotified. Consider wrapping each listener invocation in try-catch to ensure all listeners are notified even if one fails.

🔎 Proposed defensive wrapper
-    this.invalidationListeners.forEach((listener) => listener());
+    this.invalidationListeners.forEach((listener) => {
+      try {
+        listener();
+      } catch (err) {
+        logger.error('Error in invalidation listener:', err);
+      }
+    });
code/builders/builder-vite/src/plugins/code-generator-plugin.ts (1)

69-89: LGTM with minor observation: Consistent async handling.

The switch-based approach cleanly separates the handling of different virtual modules. However, note that the iframeId case at lines 84-88 uses readFileSync (which is actually async in this context via the existing readFileSync import from node:fs), but the import at line 1 shows it's from 'node:fs' which is synchronous. Consider whether async file reading would be more consistent.

Optional: Use async file reading for consistency
+import { readFile } from 'node:fs/promises';
-import { readFileSync } from 'node:fs';

 case iframeId: {
-  return readFileSync(
+  return await readFile(
     fileURLToPath(importMetaResolve('@storybook/builder-vite/input/iframe.html')),
     'utf-8'
   );
 }
code/core/src/core-server/utils/watch-story-specifiers.test.ts (1)

23-35: Timer setup and teardown are appropriate for batched watcher behavior

Using fake timers in setup, a shared flushEvents helper, and restoring real timers plus closing the watcher in teardown gives deterministic coverage of the new batching logic without leaking timers or watchers across tests.

Also applies to: 91-95

code/core/src/csf-tools/vitest-plugin/transformer.test.ts (1)

599-649: Component info extraction coverage is focused and useful

The new tests validating componentPath and componentName for named, default, and aliased imports give good confidence that the transformer computes the correct metadata for typical React component imports.

code/addons/vitest/src/vitest-plugin/test-utils.ts (1)

34-52: testStory object API and meta extensions look consistent

The switch to a single options object and the addition of componentPath / componentName on task.meta align with the updated transformer output and give downstream consumers access to the new metadata without changing runtime behavior for existing callers. If you want to keep meta minimal, you could optionally only assign the component fields when they are defined, but it is not required.

Also applies to: 77-83, 89-90

code/builders/builder-vite/src/virtual-file-names.ts (1)

7-15: Virtual file ID helpers align with Vite-style resolution

Exposing SB_VIRTUAL_FILE_IDS and using a simple leading-character slice to recover the original ID from the resolved form is consistent with \0-prefixed virtual ids and should work cleanly as long as callers only pass strings produced by getResolvedVirtualModuleId.

Comment thread code/builders/builder-vite/src/codegen-importfn-script.ts
Comment thread code/builders/builder-vite/src/plugins/code-generator-plugin.ts
Comment thread code/builders/builder-vite/src/plugins/code-generator-plugin.ts
Comment thread code/core/src/core-server/presets/common-preset.ts
Comment thread code/core/src/core-server/utils/index-json.ts
@yannbf yannbf force-pushed the yann/ghost-stories-research branch from badd420 to 5a0395e Compare December 22, 2025 10:29
@yannbf yannbf merged commit 940ad62 into yann/ghost-stories-research Dec 22, 2025
62 of 67 checks passed
@yannbf yannbf deleted the yann/improved-vitest-meta branch December 22, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants