nuxt / nuxt/test-utils

Vitest workspaces in a monorepo doesn't work.

Open
#1,307 3 comments 2 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: Windows_NT
  • Node Version: v22.13.1
  • Nuxt Version: 3.17.4
  • CLI Version: 3.25.1
  • Nitro Version: 2.11.12
  • Package Manager: npm@11.4.1
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

repo - runs when checked out locally (npm i && npm t)
stackblitz - doesn't run for some reason, maybe something related to the stackblitz template provided by this issue creation tool.

Describe the bug

When we are in a monorepo with multiple packages (regulars, nuxt layers) and we want to run tests from root the nuxt layer package tests are failing because nuxt features doesn't work (no auto import, no layer aliases, ...).

At root level we have a plain vitest config using defineConfig and setting workspace option. This correctly picks up individual package vitest.config.ts files. Nuxt layer packages use defineVitestProject.

Running npm t in the actual nuxt layer packages everything works as it should (nuxt features are working).

It is also interesting that we had to install nuxt at root level, but maybe that is fine.

Another interesting thing we noticed that each nuxt layer package runs test from all layers which we don't want so added exlude patterns in those vitest configs.

Additional context

No response

Logs

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 root Vitest config using defineConfig and the workspace option, then compare it with each package's vitest.config.ts using defineVitestProject. Run npm t from the repository root and from an individual Nuxt layer package to compare behavior. Done means Nuxt features work for layer tests from the root without unintentionally running tests from other layers.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.