-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Use closest vitest.config.ts
from the test file for mono repo
#13
Comments
Yes! In my setup, each sub-package has it's own vitest.config.ts file and its own test command. However, the CWD is defaulting to the root monorepo dir. |
Hi! I'm also using monorepo. I have thoughts for other kind of setup (inspired by turborepo example) where:
Not sure if this kind of setup is a good idea, here's a sample from turborepo, it's jest but I think it's similar. |
The same here, I use turborepo for monorepo, and just some packages in it using vitest, I don't want to put vitest config to root dir. |
+1 |
Same. I can't use the extension in my turborepo without this enhancement |
Same issue here |
+1 |
Plugin test fail when monorepo workspace config has both sub package and root enhancement vitest-dev#13
Plugin test fail when monorepo workspace config has both sub package and root enhancement #13
As a note: setting commandLine to something like I'd imagine the desired solution here would be something like what dbaeumer.vscode-eslint does with the |
Same here turborepo & vitest, will be extremely useful, its a blocker for us from using the vscode extension |
+1 can't use the extension with my monorepo :/ |
Add me to the camp of people who would love to use this, but can't because we use vitest in a monorepo |
I've tackled some issues about vitest not detecting the correct path when starting (#88), and I think that this problem may be related. The monorepo samples of this project seems broken, can one of you please try it on your machine?
Thanks! |
Any update? I need to use it with Turborepo. |
If you use vscode workspaces (honestly you should if you use any monorepo). // file: ROOT/.vscode/project-name.code-workspace
{
"folders": [
{
"name": "Project-name",
"path": "../"
},
{
"name": "App 1",
"path": "../apps/first"
},
{
"name": "Package 1",
"path": "../packages/first"
}
],
"settings": {
"vitest.commandLine": "pnpm exec vitest",
// these settings are applied to all workspaces
}
} |
Hi guys, We made good progress on #125 which should resolve this kind of issue. Could you try it on your machine to see it fix your issue? |
You need to open the workspace. You can either run |
Hi guys! The PR has been merged, can you try v0.2.39 and let us know if it solved your issues? If not, please open the output tab > vitest and past the logs to help us debug. |
hey @ngirardin, I just tried but it looks like it doesn't detect the version correctly... Or do I missing something? Thank you |
@tomtobac could you open the terminal pane, go to the output tab, select « vitest » and paste the logs here? |
Basically the same as the popup :/ |
@ngirardin here is my log. I'm in NX monorepo.
I'm able to run tests in cli with: My actual monorepo root is: |
/usr/local/bin/node ./node_modules/vitest/vitest.mjs [ProjectRootPath] [vitest.commandLine] [ProjectRootPath]/apps/Somepackage/src/utils/__tests__/sometest.test.ts --api.port 64217 --api.host 127.0.0.1
DEV v0.28.5 [ProjectRootPath]
API started at http://127.0.0.1:64217
❯ packages/testing/__tests__/sometest.test.ts (0 test)
❯ apps/Somepackage/src/utils/__tests__/some-other-test.test.ts (0 test)
⎯⎯⎯⎯⎯⎯ Failed Suites 2 ⎯⎯⎯⎯⎯⎯⎯
FAIL packages/testing/__tests__/some-other-test.test.ts [ packages/testing/__tests__/some-other-test.test.ts ] Running into similar issues. The plugin can't find any tests in the testfiles. Commandline works. I added a workspace file and put the |
+1 |
Worked for me thank you. I had to use include inside config, and used command line to specify the config. Otherwise |
@diginikkari
this is debug mode that does not work.
cli works with |
Debug is currently not working with my setup. I am using turborepo with pnpm Root pnpm-workspace.yaml: packages:
- "*"
# exclude packages that are inside test directories etc
- "!**/test/**"
- "!.vscode"
- "!node_modules" Root turbo.json: {
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"inputs": ["src/**"],
"outputs": ["lib/**"],
"dependsOn": ["^build"]
},
"test": {
"inputs": ["src/**", "__tests__/**"],
"dependsOn": ["package"]
},
"lint": {},
"format": {},
"format-check": {},
"package": {
"inputs": ["src/**", "lib/**"],
"outputs": ["dist/**"],
"dependsOn": ["build"]
},
"all": {}
}
} package vitest.config.ts: import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
clearMocks: true,
environment: "node",
},
});
VS Code output from Vitest:
|
[Workaround] /workspace/.vscode/settings.json {
"vitest.enable": true,
"vitest.commandLine": "/usr/bin/node /workspace/app-3/node_modules/.bin/vitest --root /workspace/app-3"
} VSCode: 1.80.0
OS: Linux 45ed49a584cc 5.4.49-050449-generic #202006241630 SMP Wed Jun 24 16:36:16 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
nodejs: v18.16.1
npm: 9.7.2
vite: 4.4.2
vitest: 0.32.4
vue: 3.3.4
zixuanchen.vitest-explorer: v0.2.42 $ pwd
/workspace
$ /usr/bin/node /workspace/app-3/node_modules/.bin/vitest --root /workspace/app-3 --run
RUN v0.32.4 /workspace/app-3
✓ src/components/__tests__/HelloWorld.spec.ts (1)
✓ HelloWorld (1)
✓ renders properly
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 12:00:42
Duration 1.01s (transform 167ms, setup 0ms, collect 124ms, tests 19ms, environment 298ms, prepare 172ms) $ ls -a /workspace/
. .. app-3 .devcontainer .git .gitignore LICENSE .prettierrc README.md .vscode
# This is a sample project generated by `npm init vue@latest` with name `app-3`.
ls /workspace/app-3/
e2e index.html package.json playwright.config.ts public src tsconfig.app.json tsconfig.node.json vite.config.ts
env.d.ts node_modules package-lock.json playwright-report README.md test-results tsconfig.json tsconfig.vitest.json vitest.config.tsz` |
This works pretty well with my turborepo project, as long as I don't configure my root folder as a separate folder of the code-workspace file. If I do that, every single test (leaf) successfully runs, but the root/parent test (with the name "Test run at , ") remains in the loading/waiting state infinitely unless I click the stop button. Then it switches to success (if all its child tests were successful). Removing the root folder from the workspace config is a temporary workaround, but I'd prefer not having to remove it. Any ideas what could help? |
I'm in a repository / VS code workspace with two projects, each of which is in a top-level folder:
I can easily run tests from inside the root folder using The result is always:
I'm having the feeling the extension might not even pick up my settings correctly. Anyway, I just discovered vitest workspaces. While I haven't been able to get them to work (yet), at least now vitest CLI and the VSCode extension behave identically and both show the same error (something about duplicate/conflicting dependencies in my code), so I will continue to investigate this path. |
For now there isnt a way to set a configuration file for a package inside a monorepo.
#6 (comment)
Thanks!
The text was updated successfully, but these errors were encountered: