Environment
|
|
| Operating system |
Windows 10.0.26200 |
| CPU |
13th Gen Intel(R) Core(TM) i3-1315U (8 cores) |
| Node.js version |
v22.23.1 |
| nuxt/cli version |
3.37.0 |
| Package manager |
npm@10.9.8 |
| Nuxt version |
4.5.1 |
| Nitro version |
2.13.4 |
| Builder |
vite@8.2.0 |
| Config |
- |
| Modules |
- |
Reproduction
https://github.com/nuxt/starter/tree/module
Describe the bug
Summary
The module starter template (nuxt/starter#module) does not include a
vitest.config.ts file. With the release of @nuxt/test-utils v4, this
omission causes test failures because the Nuxt vitest environment must now be
explicitly configured via defineVitestConfig or defineVitestProject.
Current behavior
Running npm run test (or vitest) on a freshly scaffolded module project
results in:
Cannot read properties of undefined (reading 'config') at test/basic.test.ts:5:1
This happens because:
- No
vitest.config.ts is present → vitest runs without a nuxt environment
@nuxt/test-utils v4 moved Nuxt environment setup from setupFiles to
beforeAll, so any Nuxt composable or setup() call at the top level of
a describe block throws before the environment is initialized
Expected behavior
The module starter template should ship with a vitest.config.ts that correctly
configures the test environment for @nuxt/test-utils v4, following the
official testing docs.
Proposed vitest.config.ts
import { defineConfig } from 'vitest/config'
import { defineVitestProject } from '@nuxt/test-utils/config'
export default defineConfig({
test: {
projects: [
{
test: {
name: 'unit',
include: ['test/unit/*.{test,spec}.ts'],
environment: 'node',
},
},
await defineVitestProject({
test: {
name: 'nuxt',
include: ['test/nuxt/*.{test,spec}.ts'],
environment: 'nuxt',
environmentOptions: {
nuxt: {
rootDir: './playground',
},
},
},
}),
],
},
})
Additional context
Additional notes
package.json should have "type": "module" for ESM compatibility
with the config file (or the file should be renamed to vitest.config.mts)
- Test files should be reorganized under
test/nuxt/ for Nuxt-environment
tests and test/e2e/ for end-to-end tests using setup() from
@nuxt/test-utils/e2e
- The existing
test/basic.test.ts in the template should be moved to
test/nuxt/basic.test.ts
Environment
@nuxt/test-utils: v4.x
vitest: v4.x
- Template:
nuxt/starter#module
References
Environment
Windows 10.0.2620013th Gen Intel(R) Core(TM) i3-1315U (8 cores)v22.23.13.37.0npm@10.9.84.5.12.13.4vite@8.2.0--Reproduction
https://github.com/nuxt/starter/tree/module
Describe the bug
Summary
The module starter template (
nuxt/starter#module) does not include avitest.config.tsfile. With the release of@nuxt/test-utilsv4, thisomission causes test failures because the Nuxt vitest environment must now be
explicitly configured via
defineVitestConfigordefineVitestProject.Current behavior
Running
npm run test(orvitest) on a freshly scaffolded module projectresults in:
This happens because:
vitest.config.tsis present → vitest runs without anuxtenvironment@nuxt/test-utilsv4 moved Nuxt environment setup fromsetupFilestobeforeAll, so any Nuxt composable orsetup()call at the top level ofa
describeblock throws before the environment is initializedExpected behavior
The module starter template should ship with a
vitest.config.tsthat correctlyconfigures the test environment for
@nuxt/test-utilsv4, following theofficial testing docs.
Proposed
vitest.config.tsAdditional context
Additional notes
package.jsonshould have"type": "module"for ESM compatibilitywith the config file (or the file should be renamed to
vitest.config.mts)test/nuxt/for Nuxt-environmenttests and
test/e2e/for end-to-end tests usingsetup()from@nuxt/test-utils/e2etest/basic.test.tsin the template should be moved totest/nuxt/basic.test.tsEnvironment
@nuxt/test-utils: v4.xvitest: v4.xnuxt/starter#moduleReferences
@nuxt/test-utilsv4.0.0 release notesbeforeAll(#1516)