-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
globalSetup script is executed with wrong CWD #6706
Comments
Is this duplicate of #5277? |
Though global setup is executed in the main thread. Maybe we could do something like const cwd = process.cwd()
process.chdir(dirname(<project-config-location>))
await import(<project-global-setup>)
process.chdir(cwd) But would this just cause confusion as other fields of project's configuration are not relative to configuration file's location? 🤔 |
It indeed appears so - sorry I failed to find that issue when searching for duplicates. The following seems to be a sufficient workaround for my case. It was just a surprising behavior. export async function setup(context: GlobalSetupContext): Promise<() => Promise<void>> {
// Workaround for https://github.com/vitest-dev/vscode/issues/503
if (process.cwd() !== context.config.root) {
process.chdir(context.config.root);
}
// ...rest of global setup
} |
We might be able to
|
Describe the bug
When using
vitest.workspace.ts
file in a monorepo, theglobalSetup
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
Clone this repository & install dependencies (or use Stackblitz):
git clone https://github.com/maxpatiiuk/vitest-wrong-cwd cd vite-wrong-cwd npm install
Run
npx vitest run
from monorepo root. See that thevite.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
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: