-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
In an nx monorepo set the working directory to the package directory #254
Comments
I don't think this is in the scope of this extension. Vitest itself doesn't support nx integration, it has its own workspace support. |
But when we have a vitest.workspace.ts file, is Vitest's behavior then to set the root directory to the workspace folder, or the root folder? Either way, I think I'll update the NX sample to mimick NX behavior more. I think it's doable. |
|
@sheremet-va when you say "We cannot support nx vitest behavior though." do you mean in this extension or generally in vitest? Having thought about it some more I can clearly see that this, as you said, is beyond the scope of this extension. The issue here would seem to stem from the fact that nx will change directory into the package directory when running package commands whereas vitest will not do this, even in the presence of a vitest workspaces file. Is it worth opening a discussion on this in the vitest repo? From reading the vitest workspaces docs and in particular this line "Vitest will consider every folder in packages as a separate project even if it doesn't have a config file inside." (emphasis mine), I think it can be argued that vitest should change directory when executing package tests. My experience here is limited, but I think this would also be consistent with other monorepo tooling (f.ex nx, npm -w). |
Yes, it should change the directory for projects. And from my knowledge, it already does so (when you use the workspace feature of course). If it doesn't for you, I would suggest opening an issue with a reproduction in Vitest repo. |
I tried everything base on the Workspace guide and no success with our monorepo. Only the
|
This is the behavior of Vitest and not the extension. The import { resolve } from 'node:path'
process.chdir(resolve('../project-1')) |
@sheremet-va I don't that is viable as you are not allow to chdir in a worker. |
Sorry, I forgot to mention to also use |
When running tests in an nx monorepo (e.g. the
monorepo-nx
sample) the working directory is set to the monorepo root. However, when the tests are executed using nx (e.g.nx run-many -t test
ornx test <package>
) the working directory is set to the package directory.Ideally the extension would be consistent with nx and change to the package directory before executing tests.
A workaround right now is to set up a multi-root vscode workspace with an entry for each package directory e.g. for the monorepo-nx sample:
The text was updated successfully, but these errors were encountered: