nuxt / test-utils

🧪 Test utilities for Nuxt
http://nuxt.com/docs/getting-started/testing
MIT License
323 stars 84 forks source link

Error updating to Vitest 2 #892

Closed alditis closed 4 months ago

alditis commented 4 months ago

Describe the feature

Vitest current version is 2.0.3. @nuxt/test-utils uses Vitest 1.0.6.

Error:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @nuxt/test-utils@3.13.1
npm ERR! Found: vitest@2.0.3
npm ERR! node_modules/vitest
npm ERR!   dev vitest@"2.0.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional vitest@"^0.34.6 || ^1.0.0" from @nuxt/test-utils@3.13.1
npm ERR! node_modules/@nuxt/test-utils
npm ERR!   dev @nuxt/test-utils@"3.13.1" from the root project
npm ERR!   @nuxt/test-utils@">=3.9.0" from vitest-environment-nuxt@1.0.0
npm ERR!   node_modules/vitest-environment-nuxt
npm ERR!     vitest-environment-nuxt@"^1.0.0" from @nuxt/test-utils@3.13.1
npm ERR! 
npm ERR! Conflicting peer dependency: vitest@1.6.0
npm ERR! node_modules/vitest
npm ERR!   peerOptional vitest@"^0.34.6 || ^1.0.0" from @nuxt/test-utils@3.13.1
npm ERR!   node_modules/@nuxt/test-utils
npm ERR!     dev @nuxt/test-utils@"3.13.1" from the root project
npm ERR!     @nuxt/test-utils@">=3.9.0" from vitest-environment-nuxt@1.0.0
npm ERR!     node_modules/vitest-environment-nuxt
npm ERR!       vitest-environment-nuxt@"^1.0.0" from @nuxt/test-utils@3.13.1
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Additional information

Final checks

dosubot[bot] commented 4 months ago

Hello, @alditis! 👋 I'm here to help you with any bugs, questions, or contributions while you're waiting for a human maintainer. Let's squash those bugs together!

To resolve the dependency conflict when updating to Vitest 2.0.3, you can modify the resolutions field in your package.json to force the version of Vitest to 2.0.3. Here is how you can do it:

"resolutions": {
  "@cucumber/cucumber": "10.7.0",
  "@nuxt/kit": "^3.11.2",
  "@nuxt/schema": "^3.11.2",
  "@nuxt/test-utils": "workspace:*",
  "rollup": "4.18.0",
  "vite": "5.2.11",
  "vue": "^3.4.27",
  "vitest": "2.0.3"
}

This will ensure that vitest is resolved to version 2.0.3, overriding any conflicting versions specified by other dependencies.

Additionally, ensure you have the correct setup in your nuxt.config and vitest.config.ts files as per the Nuxt documentation:

  1. Add @nuxt/test-utils/module to your nuxt.config file (optional):

    export default defineNuxtConfig({
     modules: [
       '@nuxt/test-utils/module'
     ]
    })
  2. Create a vitest.config.ts with the following content:

    import { defineVitestConfig } from '@nuxt/test-utils/config'
    
    export default defineVitestConfig({
     // any custom Vitest config you require
    })

By following these steps, you can manage the dependency conflict and ensure your testing environment is correctly configured [1][2][3].

To continue talking to Dosu, mention @dosu.

aethr commented 4 months ago

The advice here from @dosubot doesn't work.

This conflict was resolved in https://github.com/nuxt/test-utils/pull/888 last week, so it should be fixed in the next release.

Unfortunately nuxt/test-utils hasn't had a new release for a couple of months, hopefully the maintainer will find time to prep a release to get this fix out. :crossed_fingers:

Gugustinette commented 4 months ago

The fact that there's no release makes it kinda impossible to upgrade to Vitest 2. 😕

Also @danielroe I think the CI has a problem ? I wanted to use a nightly release (afaik they're created automatically when pushing to main) but can't find any. I looked at the Github Action and it seems like an error is throwing during nightly release : https://github.com/nuxt/test-utils/actions/runs/9997183613/job/27633175272#step:7:11

danielroe commented 4 months ago

Indeed, hopefully the maintainer will find time to prep a release.

danielroe commented 4 months ago

(Who can say ...?)

Gugustinette commented 4 months ago
Capture d’écran 2024-07-26 à 21 50 06

Feels good

danielroe commented 4 months ago

released ✅

Gugustinette commented 4 months ago

Works like a charm, thanks for handling this so fast !

aethr commented 4 months ago

Thanks @danielroe ! :heart:

Did not mean any disrespect, I genuinely appreciate the work and time you put into this.

danielroe commented 4 months ago

No disrespect received ❤️