-
-
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
When using Workspace - Run in the Context of the Project #6474
Comments
Is this duplicate of #5277? We cannot do I usually just use absolute paths there with
Yep, that's intentional and documented at https://vitest.dev/guide/workspace.html. You should use |
Ha, yes! Thank you for referencing it. I agree with what mentioned in there - this indeed leaves Vitest in an odd place compared to other mono-repo executors that support workspaces. Using absolute path is a neat trick, thanks for sharing it!
I mean scope-wise. Assuming I want to only scan the
Instead - I have to adjust it to be something like:
This is getting complex if your Mono-Repo has a complicated structure. What makes sense to me, is to have the ability to select directories I want to scan based on the root of the project, not the Workspace. But this is exactly like the bug you mentioned above. I'm closing this one, and will keep tracking the main issue. Thanks for the help @AriPerkkio ! |
Clear and concise description of the problem
Hello everyone! I want to start by saying Vitest is amazing, and I really appreciate everyone's time working on that!
I'm using the
Workspace
feature - and it feels a little bit clunky. Specifically, when using an internal vitest configuration file. For example, consider the following structure:From this point forward I will refer to
app1
andapp2
asprojects
inside theworkspace
(that's how the official documentation refers them if I understand correctly).Our unit-tests share some kind of default configuration (for example, we want all our Unit-Tests to have
restoreMock: true
). The default configuration is defined insidevitest.shared.unit
file at the root:It is being consumed by the internal
vitest.config.unit.ts
file usingdefineProject
:This works perfectly when running from within the project itself, but not if you try to run all your workspace unit-tests from the workspace root directory (using
vitest --projects='*-unit'
). The reason for that, is when running from within the workspace context, the context is the ROOT DIRECTORY of the repository.Vitest
will attempt to find test files insidetest/unit
and notapps/app1/test/unit
. That's because whileapps/app1
is defined as a project invitest.workspace.ts
, the context of the run is not from the actual project directory.This can be fixed by multiple of hacks we are tried to use (passing
dir
externally from the config file, using:dir: '${__dirname}/test/unit'
or just having some if/else inside the config file - but all of those feels pretty hacky).Another example is code-coverage. Code coverage can't be defined on the internal vitest.config file when using workspaces, only at the root
vitest.config.ts
file. Here's an example:This is a bit awkward, because instead of just stating I want to include
src
, which exists in every project I defined as part of my workspace, I need to specifically and very manually define the structure of my Workspace using wildcards and directories (even though I already defined it invitest.workspace.ts
). What I expect to work is justinclude: ["src"]
. That will verify coverage within thesrc
directory inside each of the projects.Suggested solution
I think that perhaps it's worth considering perhaps running tests from within the project context (or directory to be precise) when using Workspace. This is somehow what tools like
nx
orlerna
do.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: