Skip to content

feat: add vitest.config.ts to module starter template for @nuxt/test-utils v4 compatibility #1770

Description

@narr07

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:

  1. No vitest.config.ts is present → vitest runs without a nuxt environment
  2. @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




### Logs

```shell-script

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions