vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Run nested inline projects

Open JesusTheHun opened this issue 5 months ago • 3 comments

Clear and concise description of the problem

Let's say the root config is projects: ['packages/*'] and each package configure several inline projects to run unit tests or e2e tests, for example.

In CI, you may want to run e2e tests using the docker image provided playwright along with vitest --run --project='*:e2e'. And run the non e2e tests on the node image.

Currently, projects do not run nested projects.

In #8273, @sheremet-va made a case against running nested project through reference, but I think the case of inline projects holds.

Suggested solution

Have vitest run nested inline projects

Alternative

No response

Additional context

No response

Validations

JesusTheHun avatar Sep 06 '25 10:09 JesusTheHun

yeah this is very much needed I think. Currently it seems like if I have one package in the monorepo that needs to define 2 or more projects, the only solution is to disable the root project feature, and instead run vitest on every package individually, and merge results / coverage etc manually :(

alvarosevilla95 avatar Oct 23 '25 10:10 alvarosevilla95

This is planned as 4.1 feature.

sheremet-va avatar Oct 23 '25 12:10 sheremet-va

It would be nice if for each package project when ran at the root the project name would be derived from the package.json + config name. For example the example here https://vitest.dev/guide/projects.html#configuration

import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  test: {
    pool: 'threads',
    projects: [
      {
        // will inherit options from this config like plugins and pool
        extends: true,
        test: {
          name: 'unit',
          include: ['**/*.unit.test.ts'],
        },
      },
      {
        // won't inherit any options from this config
        // this is the default behaviour
        extends: false,
        test: {
          name: 'integration',
          include: ['**/*.integration.test.ts'],
        },
      },
    ],
  },
})

When running this from the root the name would use be @package/name/unit so if you have multiple packages with both the same projects it will work from the root.

tobeycodes avatar Nov 10 '25 01:11 tobeycodes