-
Notifications
You must be signed in to change notification settings - Fork 105
Description
Environment
- Operating System:
Darwin - Node Version:
v22.17.0 - Nuxt Version:
4.1.2 - CLI Version:
3.28.0 - Nitro Version:
2.12.6 - Package Manager:
[email protected] - Builder:
- - User Config:
compatibilityDate,devtools,modules - Runtime Modules:
@nuxt/[email protected] - Build Modules:
-
Reproduction
https://github.com/fimion/nuxt-test-utils-projects-problem
Describe the bug
When using defineConfig from vitest/config to glob import project definitions from separate config files, defineVitestProject will error out if it is used multiple times.
Example, component testing with auto mocked data vs actual endpoints.
The issue has something to do with how defineVitestProject gets run when dynamically imported by vitest and defineVitestProject will attempt to spin up a nuxt instance to get the configuration. Multiple instances attempt to run at the same time, and this causes anything after the first project read in to fail.
Additional context
We ran into this issue as we were attempting to create a way to quickly add new testing setups in a monorepo. The solution for us was one of a couple of possibilities:
- wrap
defineVitestProjectin a call using a curried method call created bylimitConcurrency(1)from@vitest/runner/utilswhich causes each call ofdefineVitestProjectto be run in sequence rather than simultaneously. - similarly, create a shared chain of promises that causes each call of
defineVitestProjectto run in sequence. - manually create a
vite-nodeinstance and read in theprojectsdefinitions manually beforevitestcan attempt to run it's process. then await each call ofdefineVitestProjectmanually.
This may be more of an upstream issue? I'm not entirely sure.
Logs
> test
> vitest --run
RUN v3.2.4 /Users/alex.riviere/WebstormProjects/nuxt-test-utils-project-collision
✓ Unit app/components/HelloWorld.unit.ts (1 test) 7ms
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL Integration app/components/HelloWorld.integration.ts [ app/components/HelloWorld.integration.ts ]
Error: Failed to resolve import "#app/nuxt-vitest-app-entry" from "node_modules/@nuxt/test-utils/dist/runtime/shared/nuxt.mjs". Does the file exist?
Plugin: vite:import-analysis
File: /Users/alex.riviere/WebstormProjects/nuxt-test-utils-project-collision/node_modules/@nuxt/test-utils/dist/runtime/shared/nuxt.mjs:3:15
1 | export async function setupNuxt() {
2 | const { useRouter } = await import("#app/composables/router");
3 | await import("#app/nuxt-vitest-app-entry").then((r) => r.default());
| ^
4 | const nuxtApp = useNuxtApp();
5 | await nuxtApp.callHook("page:finish");
❯ TransformPluginContext._formatLog node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:31527:43
❯ TransformPluginContext.error node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:31524:14
❯ normalizeUrl node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:29996:18
❯ node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:30054:32
❯ TransformPluginContext.transform node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:30022:4
❯ EnvironmentPluginContainer.transform node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:31325:14
❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:26407:26
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed | 1 passed (2)
Tests 1 passed (1)
Start at 12:04:01
Duration 736ms (transform 266ms, setup 200ms, collect 155ms, tests 7ms, environment 225ms, prepare 222ms)
Process finished with exit code 1