-
Notifications
You must be signed in to change notification settings - Fork 313
chore(deps): upgrade vitest + nuxt/test-utils #2110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
commit: |
Deploying nuxt-image with Β
|
| Latest commit: |
c3d6504
|
| Status: | Β β Β Deploy successful! |
| Preview URL: | https://0910c007.nuxt-image.pages.dev |
| Branch Preview URL: | https://chore-vitest.nuxt-image.pages.dev |
π WalkthroughWalkthroughThis change adds a new Estimated code review effortπ― 1 (Trivial) | β±οΈ ~3 minutes π₯ Pre-merge checks | β 2 | β 1β Failed checks (1 warning)
β Passed checks (2 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing touchesπ§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
π€ Fix all issues with AI agents
In `@package.json`:
- Line 63: The dependency bump to "@nuxt/test-utils" v4 introduces breaking
changes that will break tests; update package.json and test code: upgrade Vitest
to v4 and any test runners, move top-level Nuxt composable calls (useRouter,
useRoute, useNuxtApp, etc.) into beforeAll/beforeEach hooks in your test files,
revise vi.mock() factories to explicitly return all required exports or use
importOriginal() to avoid unused-export errors, and adjust peer dependencies
(happy-dom/jsdom/@jest/globals/@cucumber/cucumber/@testing-library/vue) and any
Vitest v4-specific config (module runner/coverage) accordingly so tests run
under the new v4 contracts.
- Line 87: Remove the explicit dependency "vitest-environment-nuxt" from
package.json (delete the line listing "vitest-environment-nuxt": "^1.0.1") since
it is transitively provided by `@nuxt/test-utils` v4; after removal, run your
package manager's install command (npm install / yarn install / pnpm install) to
update the lockfile and ensure no direct references remain, and then run the
test suite (or `defineVitestProject()`-based setup) to confirm the Nuxt Vitest
environment still loads via `@nuxt/test-utils`.
| "@nuxt/module-builder": "1.0.2", | ||
| "@nuxt/schema": "4.3.0", | ||
| "@nuxt/test-utils": "^3.23.0", | ||
| "@nuxt/test-utils": "^4.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π§© Analysis chain
π Web query:
@nuxt/test-utils v4 breaking changes migration guide
π‘ Result:
@nuxt/test-utils v4 (v4.0.0) breaking changes + migration checklist
1) Upgrade required deps (Vitest v4)
Update @nuxt/test-utils, vitest, and coverage packages together (v4 now requires Vitest v4). [1]
devDependencies: {
- "@nuxt/test-utils": "^3.x",
- "vitest": "^3.x",
- "@vitest/coverage-v8": "^3.x"
+ "@nuxt/test-utils": "^4.0",
+ "vitest": "^4.0",
+ "@vitest/coverage-v8": "^4.0"
}Also note tightened peer ranges (examples from the v4 release notes): happy-dom >=20.0.11, jsdom >=27.4.0, @jest/globals >=30.0.0, @cucumber/cucumber >=11.0.0, @testing-library/vue ^8.0.1. [1]
2) Nuxt test environment now starts in beforeAll (top-level composables will break)
Nuxt initialization moved from setupFiles to a beforeAll hook. If you call Nuxt composables at the top level inside a describe block, youβll now hit [nuxt] instance unavailable. Move those calls into beforeAll / beforeEach / the test body. [1]
Example:
describe('my test', () => {
let router: ReturnType<typeof useRouter>
beforeAll(() => {
router = useRouter()
})
// tests...
})Applies to useRouter(), useRoute(), useNuxtApp(), and other Nuxt auto-imports/composables. [1]
3) Stricter vi.mock factory behavior (missing exports now throw)
If you use vi.mock('...', () => ({ ... })), accessing any export you didnβt return will now throw (instead of returning undefined). Fix by spreading importOriginal() (when possible) or explicitly returning every used export. [1]
vi.mock('./module', async (importOriginal) => ({
...(await importOriginal()),
foo: 'mocked',
}))4) Vitest v4 changes you may need to account for
Nuxt Test Utils v4 switches to Viteβs native Module Runner (Vitest v4 replaced vite-node), and Vitest v4 also includes config/behavior changes (coverage defaults/options, exclude behavior, etc.). Review Vitestβs v4 migration guide for anything your setup relies on. [1][2]
Sources: Nuxt Test Utils v4.0.0 release notes/migration notes [1]; Vitest Migration Guide (Vitest 4) [2].
@nuxt/test-utils v4 has breaking changes β verify and refactor tests accordingly.
Upgrading to v4 requires Vitest v4 and introduces breaking changes that will affect existing tests:
- Top-level Nuxt composables (
useRouter(),useRoute(),useNuxtApp(), etc.) must move intobeforeAll/beforeEachhooks; they will throw "instance unavailable" at the top level. vi.mock()factories are stricter β any unused exported property will throw instead of returning undefined; useimportOriginal()or explicitly return all required exports.- Vitest v4 changes (Module Runner instead of vite-node, coverage defaults) may require adjustments to your test setup.
- Peer dependencies have tightened for
happy-dom,jsdom,@jest/globals,@cucumber/cucumber, and@testing-library/vue.
π€ Prompt for AI Agents
In `@package.json` at line 63, The dependency bump to "@nuxt/test-utils" v4
introduces breaking changes that will break tests; update package.json and test
code: upgrade Vitest to v4 and any test runners, move top-level Nuxt composable
calls (useRouter, useRoute, useNuxtApp, etc.) into beforeAll/beforeEach hooks in
your test files, revise vi.mock() factories to explicitly return all required
exports or use importOriginal() to avoid unused-export errors, and adjust peer
dependencies
(happy-dom/jsdom/@jest/globals/@cucumber/cucumber/@testing-library/vue) and any
Vitest v4-specific config (module runner/coverage) accordingly so tests run
under the new v4 contracts.
| "unbuild": "^3.6.1", | ||
| "vitest": "^3.2.4", | ||
| "vitest": "^4.0.18", | ||
| "vitest-environment-nuxt": "^1.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π§© Analysis chain
π Script executed:
# Check if vitest-environment-nuxt is actually used in test configs or test files
rg -n "vitest-environment-nuxt" --type-add 'config:*.config.*' -g '!node_modules' -g '!package.json' -g '!pnpm-lock.yaml' -g '!.lockfile'Repository: nuxt/image
Length of output: 100
π Script executed:
# Also check for references to "vitest-environment-nuxt" in config files more broadly
rg -n "vitest-environment-nuxt" . -g '!node_modules' -g '!package.json' -g '!pnpm-lock.yaml' -g '!.lockfile' 2>/dev/null | head -30Repository: nuxt/image
Length of output: 102
π Script executed:
# Check the current Vitest and `@nuxt/test-utils` versions in package.json
grep -n -E "(vitest|@nuxt/test-utils|vitest-environment-nuxt)" package.jsonRepository: nuxt/image
Length of output: 275
π Script executed:
# Look for vitest configuration in common config file locations
cat vitest.config.ts vitest.config.js vitest.config.mts nuxt.config.ts 2>/dev/null | head -100Repository: nuxt/image
Length of output: 966
π Script executed:
# Check knip.json to see why vitest-environment-nuxt is listed
cat knip.json | head -30Repository: nuxt/image
Length of output: 805
π Script executed:
# Check if there's any environment specification in the test project config
cat vitest.config.ts | grep -i "environment" -A 2 -B 2Repository: nuxt/image
Length of output: 102
π Script executed:
# Check `@nuxt/test-utils` package info to see if it bundles the environment
grep -A 5 -B 5 "environment" package.jsonRepository: nuxt/image
Length of output: 324
π Script executed:
# Search for any environment references in test files
rg "environment" test/ --type ts 2>/dev/null | head -20Repository: nuxt/image
Length of output: 36
π Script executed:
# Find the actual vitest config file
find . -name "vitest.config.*" -o -name "vitest.config.*" 2>/dev/nullRepository: nuxt/image
Length of output: 73
π Script executed:
# Check if the config shown earlier is embedded in nuxt.config or build.config
find . -name "nuxt.config.*" -o -name "build.config.*" 2>/dev/null | xargs grep -l "defineVitestProject" 2>/dev/nullRepository: nuxt/image
Length of output: 38
π Script executed:
# Let's search for where defineVitestProject is used
rg "defineVitestProject" -t ts -t js 2>/dev/nullRepository: nuxt/image
Length of output: 36
π Script executed:
# Check the knip.json more completely to understand the ignoreDependencies setting
cat knip.jsonRepository: nuxt/image
Length of output: 1356
π Script executed:
# Read the vitest.config.mts file to see the full config
cat vitest.config.mtsRepository: nuxt/image
Length of output: 966
π Script executed:
# Check if `@nuxt/test-utils` provides a built-in environment
rg "environment" --type ts --type js -g '!node_modules' 2>/dev/null | grep -i nuxtRepository: nuxt/image
Length of output: 36
π Script executed:
# Check what `@nuxt/test-utils` declares as dependencies in its package.json
npm view `@nuxt/test-utils`@4.0.0 dependencies 2>/dev/null | head -50Repository: nuxt/image
Length of output: 771
π Script executed:
# Check if vitest-environment-nuxt is mentioned in `@nuxt/test-utils` peer dependencies
npm view `@nuxt/test-utils`@4.0.0 peerDependencies 2>/dev/nullRepository: nuxt/image
Length of output: 324
π Script executed:
# Check Vitest v4 changelog or docs for environment changes
web_search
Vitest v4 environment API changes from v3Repository: nuxt/image
Length of output: 149
π Web query:
@nuxt/test-utils v4 vitest-environment-nuxt
π‘ Result:
With @nuxt/test-utils v4, you generally do not need the separate vitest-environment-nuxt packageβNuxtβs Vitest environment is provided via @nuxt/test-utils/config, and you enable it with environment: 'nuxt'. [1][2]
Recommended (Vitest projects) setup
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import { defineVitestProject } from '@nuxt/test-utils/config'
export default defineConfig({
test: {
projects: [
{
test: { name: 'unit', environment: 'node' },
},
await defineVitestProject({
test: { name: 'nuxt', environment: 'nuxt' },
}),
],
},
})[2]
Simple setup (all tests in Nuxt environment)
// vitest.config.ts
import { defineVitestConfig } from '@nuxt/test-utils/config'
export default defineVitestConfig({
test: {
environment: 'nuxt',
},
})[2]
Per-file opt-in (or opt-out)
// `@vitest-environment` nuxtand if you set environment: 'nuxt' globally, you can opt out with:
// `@vitest-environment` node[1][2]
Where vitest-environment-nuxt fits
vitest-environment-nuxt is associated with the older nuxt-vitest setup (its docs show defineVitestConfig coming from nuxt-vitest/config). If youβre on @nuxt/test-utils v4, prefer the Nuxt docs configuration above. [3]
Sources: Nuxt testing docs and npm package pages. [1][2][3]
Remove vitest-environment-nuxt from package.jsonβit's a transitive dependency of @nuxt/test-utils v4 and already flagged as ignored.
vitest-environment-nuxt is included as a dependency of @nuxt/test-utils v4 and does not need explicit listing in package.json. The knip.json config already marks it under ignoreDependencies, confirming it's not directly used. Removing it will clean up the dependency tree without affecting functionality, as the Nuxt environment is provided through @nuxt/test-utils/config's defineVitestProject().
π€ Prompt for AI Agents
In `@package.json` at line 87, Remove the explicit dependency
"vitest-environment-nuxt" from package.json (delete the line listing
"vitest-environment-nuxt": "^1.0.1") since it is transitively provided by
`@nuxt/test-utils` v4; after removal, run your package manager's install command
(npm install / yarn install / pnpm install) to update the lockfile and ensure no
direct references remain, and then run the test suite (or
`defineVitestProject()`-based setup) to confirm the Nuxt Vitest environment
still loads via `@nuxt/test-utils`.
π Linked issue
β Type of change
π Description