nuxt / nuxt/test-utils

Nuxt 4 + Layers breaks Nuxt Test Utils

Open
#1,288 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
Dominant language
TypeScript
Stars
437
Forks
120
Avg merge
22h 52m
Merged PRs (30d)
23

Description

Environment
- Operating System: Linux
- Node Version:     v20.16.0
- Nuxt Version:     3.17.2
- CLI Version:      3.25.0
- Nitro Version:    2.11.11
- Package Manager:  npm@10.8.1
- Builder:          -
- User Config:      modules, devtools, compatibilityDate
- Runtime Modules:  @nuxt/test-utils/module@3.18.0
- Build Modules:    -
Reproduction

Github repo: https://github.com/wuiyang/nuxt-layer-test-bug
Stackblitz: https://stackblitz.com/~/github.com/wuiyang/nuxt-layer-test-bug

Describe the bug

When project root is using Nuxt 4 version (via config future.compatibilityVersion = 4), nuxt test utils would not work on layers within same project.

Image

The unit test would run without console error log, but the test report would show there is an error:

TypeError: Cannot read properties of undefined (reading 'vueApp')

When project root is not using Nuxt 4 version, the nuxt test utils would work as expected.
See reproduction repo:

Additional context

No response

Logs
abc@efac4cbfa0a5:/..../nuxt-layer-test-bug$ npx vitest run --coverage
 Vitest  "environmentMatchGlobs" is deprecated. Use "workspace" to define different configurations instead.
 HTML  Report is generated
       You can run npx vite preview --outDir ../test-reports/unit-test to see the test results.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and its package.json, comparing the working-without-nuxt-4 branch with the configuration using future.compatibilityVersion = 4. Run npx vitest run --coverage and verify that tests for layers complete without the undefined vueApp error and produce a valid report.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.