Open jinyongp opened 4 months ago
Hey there, @jinyongp! 👋 I'm here to help you out with any bugs, questions, or becoming a contributor. Let's squash those bugs together!
To ensure that the vitest.config.ts
file is automatically loaded when using @nuxt/test-utils/module
in your Nuxt 3 project, you should define the configuration using defineVitestConfig
from @nuxt/test-utils/config
. Here is an example configuration:
// vitest.config.ts
import { defineVitestConfig } from '@nuxt/test-utils/config'
export default defineVitestConfig({
test: {
globals: true,
silent: true,
environment: 'nuxt',
include: [
'server/**/*.test.ts',
],
exclude: [
'**/-*.*',
],
}
})
Additionally, ensure that your nuxt.config.ts
is correctly set up to include the @nuxt/test-utils/module
and the testUtils
property:
// nuxt.config.ts
export default defineNuxtConfig({
devtools: { enabled: true },
modules: [
'@nuxt/test-utils/module'
],
testUtils: {
startOnBoot: true,
logToConsole: true,
vitestConfig: {
// No need to specify the config path here
}
}
})
If the vitest.config.ts
is still not being applied, make sure that your vitest.config.ts
file is named correctly and located in the root directory of your project. Also, ensure that your package.json
has "type": "module"
specified, or rename your configuration file to vitest.config.mts
if you are using TypeScript.
If you continue to experience issues, it might be related to a known issue where the vitest.config.ts
file is not automatically loaded. In such cases, you can explicitly import and apply the configuration in your nuxt.config.ts
:
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt'
import vitestConfig from './vitest.config.ts'
export default defineNuxtConfig({
devtools: { enabled: true },
modules: [
'@nuxt/test-utils/module'
],
testUtils: {
startOnBoot: true,
logToConsole: true,
vitestConfig: vitestConfig
}
})
This should ensure that the vitest.config.ts
configuration is applied correctly when running your tests with Nuxt [1].
To continue talking to Dosu, mention @dosu.
duplicate #837
the issue has not been solved yet, so I will keep it open.
Environment
Build Modules: -
Reproduction
Reproduction on CodeSandbox
Describe the bug
After adding
@nuxt/test-utils/module
tonuxt.config.ts
, thevitest.config.ts
file in the root directory is not automatically loaded. Even when explicitly specifyingvitestConfig.config
in thetestUtils
property, thevitest.config.ts
is not being applied.Here is the configuration:
I have observed a difference in the results when running tests directly with vitest and running them via nuxt dev.
Additional context
No response
Logs
No response