vitest-dev / vitest-dev/vitest
"cwd" is workspace root when running tests in sub directory projects
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 92
Description
UPDATE: current workaround with pool: "forks" and setupFiles looks like this https://stackblitz.com/edit/vitest-dev-vitest-xedeud?file=packages%2Flib1%2Fvite.config.ts
Describe the bug
I've seen a similar behavior while I was investigating https://github.com/vitest-dev/vitest/discussions/5003, but I suppose this is not an intended behavior according to https://github.com/vitest-dev/vscode/issues/254#issuecomment-1953750603
In the reproduction, I also checked cwd when loading config. Following logs are from running console.log({ url: import.meta.url, cwd: process.cwd() }) in config files and test files:
❯ npx vitest run
{
url: 'file:///home/projects/vitest-dev-vitest-4fbeln/packages/lib1/vite.config.ts',
cwd: '/home/projects/vitest-dev-vitest-4fbeln'
}
{
url: 'file:///home/projects/vitest-dev-vitest-4fbeln/packages/lib2/vite.config.ts',
cwd: '/home/projects/vitest-dev-vitest-4fbeln'
}
RUN v1.3.1 /home/projects/vitest-dev-vitest-4fbeln
stdout | test/square.test.ts > square
{
url: 'file:///home/projects/vitest-dev-vitest-4fbeln/packages/lib2/test/square.test.ts',
cwd: '/home/projects/vitest-dev-vitest-4fbeln'
}
stdout | test/double.test.ts > double
{
url: 'file:///home/projects/vitest-dev-vitest-4fbeln/packages/lib1/test/double.test.ts',
cwd: '/home/projects/vitest-dev-vitest-4fbeln'
}
✓ |lib2| test/square.test.ts (1)
✓ |lib1| test/double.test.ts (1)
Test Files 2 passed (2)
Tests 2 passed (2)
Start at 10:08:30
Duration 2.30s (transform 67ms, setup 0ms, collect 54ms, tests 6ms, environment 0ms, prepare 598ms)
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-4fbeln?file=packages%2Flib2%2Ftest%2Fsquare.test.ts
System Info
(stackblitz)
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.18.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.14.0 - /usr/local/bin/pnpm
npmPackages:
@vitest/ui: latest => 1.3.1
vite: latest => 5.1.4
vitest: latest => 1.3.1
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked StackBlitz reproduction and compare process.cwd() in the packages/lib1 and packages/lib2 vite.config.ts and test files. Trace how Vitest loads each project when running from the workspace root. Done means cwd reflects the relevant subdirectory project rather than the workspace root, while preserving the reported test behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript, vite
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100