Skip to content

globalSetup script is executed with wrong CWD #6706

@maxpatiiuk

Description

@maxpatiiuk

Describe the bug

When using vitest.workspace.ts file in a monorepo, the globalSetup script is executed with the CWD set to the monorepo root rather than the package root.

The vite.config.ts is correctly executed with the package root as CWD.

Reproduction

https://stackblitz.com/~/github.com/maxpatiiuk/vitest-wrong-dir

  1. Clone this repository & install dependencies (or use Stackblitz):

    git clone https://github.com/maxpatiiuk/vitest-wrong-cwd
    cd vite-wrong-cwd
    npm install
  2. Run npx vitest run from monorepo root. See that the vite.config.ts is correctly executed with CWD set to package root. At the same time, globalSetup script is unexpectedly executed with CWD set to the monorepo root.

System Info

System:
    OS: macOS 14.7
    CPU: (10) arm64 Apple M1 Pro
    Memory: 501.66 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v20.16.0/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
    pnpm: 8.9.0 - ~/.nvm/versions/node/v20.16.0/bin/pnpm
  Browsers:
    Chrome: 129.0.6668.100
    Safari: 18.0.1
  npmPackages:
    vite: 5.4.8 => 5.4.8 
    vitest: 2.1.2 => 2.1.2

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: workspaceIssues and PRs related to the workspace feature

    Type

    No type

    Projects

    Status

    Rejected

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions