Skip to content
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

Vitest Workspaces don't respect multiple configs in a single workspace package #5530

Closed
6 tasks done
conallroli opened this issue Apr 12, 2024 · 2 comments · Fixed by #6316
Closed
6 tasks done

Vitest Workspaces don't respect multiple configs in a single workspace package #5530

conallroli opened this issue Apr 12, 2024 · 2 comments · Fixed by #6316
Labels
feat: workspace Issues and PRs related to the workspace feature p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@conallroli
Copy link

Describe the bug

I've got a monorepo with a few packages in it. In one of those packages, I need to use two different testing setups (it's an electron app so there's both main process and renderer process setups required).

When running the tests through vitest's workspace feature, I've noticed that it gathers all the config files listed in the vitest.workspace.js file, but only uses the first config file for a given package. I've made a minimal repo here

@sheremet-va has helpfully provided a workaround to this issue. You can just put the other config file in a different folder, then adjust your includes as appropriate. Example here.

Reproduction

https://github.com/conallroli/vitest-workspace-repro

System Info

System:
    OS: macOS 13.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 65.48 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 4.1.1 - ~/.nvm/versions/node/v20.11.1/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  Browsers:
    Chrome: 123.0.6312.122
    Safari: 16.3
  npmPackages:
    vitest: ^1.5.0 => 1.5.0

Used Package Manager

yarn

Validations

@sheremet-va sheremet-va added p3-minor-bug An edge case that only affects very specific usage (priority) feat: workspace Issues and PRs related to the workspace feature and removed pending triage labels Apr 12, 2024
@douglasg14b
Copy link

douglasg14b commented Jun 14, 2024

@sheremet-va Is this a minor bug? It's a full-stop blocker for testing with workspaces if the requirement is having two separate test setups (ie. unit vs blackbox).

This also stops --project flags from working for the projects it's skipping.

The workaround in the OP appears to function when you know the exact config path, but it does not appear to be working with globs 🤔

Edit: Got it working with globs 👍

@amitz
Copy link

amitz commented Aug 6, 2024

Another vote from me about this should be prioritised higher. Even if using two separated directories as mentioned in the workaround, this is rather complex to set-up.

Consider the following structure:

|-- src
|   |-- projectA
|       |-- test
|            |-- integration
|                |-- vitest.config.integration.ts
|            |-- unit
|                |-- vitest.config.unit.ts

For the workaround to work, the workspace directories should be src/projectA/test/integration and src/projectB/test/unit. Assuming you have tests inside, all you have to do is to set you config include to **/*.spec.ts. This will work when using Workspace to run your tests. But if you want to run the tests from the project directory (src/projectA) - and you're running vitest from that directory, the included **/*.spec.ts will catch both types of tests, because the working directory has changed. This can be solved with --root, but it's very fiddly and confusing.

More details and a working example can be found in here in case anyone find it useful 😄

@sheremet-va sheremet-va added p4-important Violate documented behavior or significantly improves performance (priority) and removed p3-minor-bug An edge case that only affects very specific usage (priority) labels Aug 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: workspace Issues and PRs related to the workspace feature p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants