Skip to content

Conversation

@ghengeveld
Copy link
Member

@ghengeveld ghengeveld commented Dec 9, 2025

Closes #

What I did

In the automigration from Nextjs to Nextjs-Vite, add vite as a devDependency if it isn't installed yet. This prevents the project from breaking in case it wasn't previously using Vite yet.

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 pull request has been released as version 0.0.0-pr-33316-sha-bb47faf7. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-33316-sha-bb47faf7
Triggered by @valentinpalkovic
Repository storybookjs/storybook
Branch nextjs-vite-automigration-add-vite
Commit bb47faf7
Datetime Wed Dec 10 14:40:14 UTC 2025 (1765377614)
Workflow run 20102391382

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

Summary by CodeRabbit

  • New Features
    • Enhanced Next.js to Vite migration with improved dependency management. The migration now automatically installs Vite (^7.0.0) when it's not already present in your project, while intelligently detecting and skipping reinstallation if Vite is already installed. This streamlines the setup process and reduces manual configuration requirements.

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

@nx-cloud
Copy link

nx-cloud bot commented Dec 9, 2025

View your CI Pipeline Execution ↗ for commit bb47faf

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

☁️ Nx Cloud last updated this comment at 2025-12-10 13:40:07 UTC

@valentinpalkovic
Copy link
Contributor

@copilot fix the unit tests

Copy link
Contributor

Copilot AI commented Dec 9, 2025

@valentinpalkovic I've opened a new pull request, #33318, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 4 commits December 9, 2025 18:18
- Add getDependencyVersion mock to package manager in tests
- Split test into two scenarios: with and without vite installed
- Test that vite@^7.0.0 is added when vite is not installed
- Test that vite is not added when already installed

Co-authored-by: valentinpalkovic <[email protected]>
- Add VITE_DEFAULT_VERSION constant in both implementation and tests
- Add comment explaining explicit mock setup in test for clarity
- Update test to use constant instead of hardcoded version

Co-authored-by: valentinpalkovic <[email protected]>
- Export constant from main file to maintain single source of truth
- Import constant in test file instead of duplicating
- Remove redundant mock setup that was already done in beforeEach

Co-authored-by: valentinpalkovic <[email protected]>
@valentinpalkovic
Copy link
Contributor

@copilot Please fix the type errors:
code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts:50:72 - error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string | null'.

50 vi.mocked(mockPackageManager.getDependencyVersion).mockReturnValue(undefined);
~~~~~~~~~

yarn exec jiti ./scripts/check/check-package.ts --cwd code/lib/cli-storybook

code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts:50:72 - error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string | null'.

50 vi.mocked(mockPackageManager.getDependencyVersion).mockReturnValue(undefined);

Copy link
Contributor

Copilot AI commented Dec 10, 2025

@valentinpalkovic I've opened a new pull request, #33321, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits December 10, 2025 07:05
Nextjs-Vite: Install `vite` during migration if not installed yet
@valentinpalkovic valentinpalkovic marked this pull request as ready for review December 10, 2025 11:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 10, 2025

📝 Walkthrough

Walkthrough

The changes modify the Next.js to Next.js Vite migration fixer to automatically install Vite with a default version (^7.0.0) if it is not already present. Tests are updated to mock dependency version detection and validate both scenarios: when Vite is installed and when it is not.

Changes

Cohort / File(s) Summary
Vite Default Version Constant
code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts
Adds new exported constant VITE_DEFAULT_VERSION = '^7.0.0' and conditionally includes vite installation during migration if vite is not already present.
Test Coverage Updates
code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts
Imports VITE_DEFAULT_VERSION, mocks getDependencyVersion on JsPackageManager, and adds test cases for scenarios where vite is installed and where it is absent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify that VITE_DEFAULT_VERSION value (^7.0.0) aligns with project standards and Vite compatibility requirements
  • Confirm getDependencyVersion mock is consistently configured across all test cases
  • Review conditional logic ensures vite is only added when not already installed
✨ Finishing touches
  • 📝 Generate docstrings

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

Copy link
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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts (1)

11-32: Consider using spy: true for package mocks.

The mock declarations don't use the spy: true option, which deviates from the project's mocking guidelines. However, for external dependencies like node:fs/promises that shouldn't execute real I/O in tests, full mocking may be more appropriate than spying.

Based on learnings and coding guidelines, consider updating the mocks to use spy: true if partial spying is acceptable:

-vi.mock('node:fs/promises', () => ({
-  readFile: vi.fn(),
-  writeFile: vi.fn(),
-}));
+vi.mock('node:fs/promises', { spy: true });

Then configure specific behaviors in beforeEach. However, this may require the actual module to be available, which might not be desirable for file system operations in tests.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5cc804 and bb47faf.

📒 Files selected for processing (2)
  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts (5 hunks)
  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts (2 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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts
  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts
**/*.{ts,tsx}

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

Enable TypeScript strict mode

Files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts
  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts
  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts
  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts
  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts
🧠 Learnings (20)
📓 Common learnings
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
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
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
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
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
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} : Mock external dependencies using vi.mock() for file system, loggers, and other external dependencies in tests
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 without the `spy: true` option in Vitest tests
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
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} : Use `vi.mock()` with the `spy: true` option for all package and file mocks in Vitest tests
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
📚 Learning: 2025-10-02T09:22:13.215Z
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts
📚 Learning: 2025-09-29T13:20:23.346Z
Learnt from: mrginglymus
Repo: storybookjs/storybook PR: 32556
File: code/core/package.json:309-313
Timestamp: 2025-09-29T13:20:23.346Z
Learning: The `fast-printf` dependency in Storybook's core package is bundled into the final distribution during the build process, so it should remain in devDependencies rather than being moved to dependencies, following the same pattern as other bundled dependencies like `open`.

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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} : Document complex mock behaviors in Vitest tests

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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 without the `spy: true` option in Vitest tests

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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} : Mock external dependencies using vi.mock() for file system, loggers, and other external dependencies in tests

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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} : Use `vi.mock()` with the `spy: true` option for all package and file mocks in Vitest tests

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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} : Use type-safe mocking with `vi.mocked()` in Vitest tests

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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 dependencies that the test subject uses

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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 direct function mocking without `vi.mocked()` in Vitest tests

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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} : Each mock implementation should return a Promise for async functions in Vitest

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.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} : Use `vi.mocked()` to type and access the mocked functions in Vitest tests

Applied to files:

  • code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts
🧬 Code graph analysis (1)
code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts (1)
code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts (2)
  • VITE_DEFAULT_VERSION (8-8)
  • nextjsToNextjsVite (38-145)
⏰ 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). (1)
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (5)
code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.ts (2)

103-108: Conditional vite installation logic looks good.

The implementation correctly checks for an existing vite installation and conditionally adds it as a devDependency when absent. The use of getDependencyVersion and the ternary spread operator is appropriate.


8-8: The Vite version specification is appropriate.

^7.0.0 is an appropriate default version. The caret operator permits installation of the latest Vite 7.x releases, including v7.2.6 (the latest stable version as of December 2025). No change needed.

code/lib/cli-storybook/src/automigrate/fixes/nextjs-to-nextjs-vite.test.ts (3)

43-50: TypeScript error fix looks good.

The mock for getDependencyVersion correctly returns null (not undefined), which resolves the TypeScript error mentioned in the PR objectives. The default behavior in beforeEach appropriately simulates the scenario where vite is not installed.


130-160: Test coverage for vite not installed scenario is correct.

The test correctly verifies that when getDependencyVersion returns null (vite not installed), both @storybook/nextjs-vite and vite@${VITE_DEFAULT_VERSION} are added as devDependencies.


162-195: Test coverage for vite already installed scenario is correct.

The test appropriately mocks getDependencyVersion to return '6.0.0' and verifies that only @storybook/nextjs-vite is added (without vite), since vite is already present.

@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Dec 10, 2025
@valentinpalkovic
Copy link
Contributor

Tested the canary. LGTM!

@valentinpalkovic valentinpalkovic merged commit cfe4488 into next Dec 10, 2025
74 of 76 checks passed
@valentinpalkovic valentinpalkovic deleted the nextjs-vite-automigration-add-vite branch December 10, 2025 20:02
@github-actions github-actions bot mentioned this pull request Dec 10, 2025
8 tasks
valentinpalkovic added a commit that referenced this pull request Dec 11, 2025
…add-vite

Nextjs-Vite: Install `vite` during migration if not installed yet
(cherry picked from commit cfe4488)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

3 participants