-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Not working properly in monorepo #110
Comments
Hi! I've had the same issue and I fixed it by creating a VSCode Workspace file. Once you have one the extension seems to pick up it needs to use the workspace root your test is in 👍 |
You mean using Multi-root workspaces? Can you show me an example? |
The project I've used that in is closed source (it's at my workplace), but it's literally just creating the file like indicated in the doc and setting one of the root path to be the folder where Vitest is installed in your repo 😉 |
Same here. Re: #81 (comment) |
I also experience this problem, arising from running in the wrong folder. On the plus side, https://github.com/kwai-explore/vscode-vitest-runner just works, although it doesn't have integration with the test explorer. The way the other one works correctly - first Running from the right folder means that tooling benefits from the test-specific tsconfig.json I have at |
Worse, however, and really must be fixed, is the poor behaviour when the vitest process fails (owing to a poorly selected working directory). The UI simply swallows errors and sits there indefinitely with spinners rather than finalising the task with an error case. Behind the scenes in the
Also this meaningful error content is completely missing from the inline-notified error if you configure the extension to create test error popups. |
A workaround is to edit the vitest command to include an explicit root. For me, adding the following to the workspace meant that at least one of the packages in the monorepo could show interactive test results correctly. "vitest.commandLine": "npx vitest --root packages/packageName/test" In terms of the This would lead to something like the following, which would mean more than one package in a monorepo could have passing tests at one time... "vitest.commandLine": "npx vitest --root ${baseDir}" |
@adrienbaron I have tried to fix this through various ways, but cannot get vscode to auto detect the workspace and find the vite.config.ts file. |
Can you please provide a more detailed answer for those of us who are still struggling. Like kasperstorgaard above asked, maybe an example or screenshot would be very helpful. |
VS Code's multi-root workspace may work for some but for many of our shared/mono repo set ups, we have one VS Code root, one Rather than a multi-root issue this seems more of |
Just messing around but here's a start: |
Can confirm all of the above Hope this feedback helps |
This workaround works for subfolders
Check logs in vitest in output it more informative Only problem i am facing now it skips env variables |
This works for me, using Vitest Workspace: import { defineWorkspace } from "vitest/config";
export default defineWorkspace(["packages/*", "apps/*"]); And nothing else. Plus, I install vitest only in monorepo root. |
I believe vitest 0.30+ introduced the concept of vitest workspaces @mrcaidev’s comment above is using the vitest.workspace.ts file as described in the vitest workspace docs. After upgrading to vitest 0.30.1 and adding the workspace file to my root dir, the vscode extension started running tests in my packages/* folder correctly. 😄 |
can you please share your setup? I did that and it's still stuck. I have vitest installed in the root package.json with pnpm, and a vitest.workspace.ts: import { defineWorkspace } from 'vitest/config'
export default defineWorkspace(['packages/*']) what's your command for |
I did not set |
Same here. I added the workspaces config file in the root of the monorepo project:
Then I made sure I was able to run |
Please provide a working example on how to setup vitest workspaces in a monorepo, with packages including other compilers then vite. After 5 hours I still can't get it to work. |
I have a few repositories for experimenting with Vitest in a monorepo setup: https://github.com/koistya/vitest-workspaces — bare minimum Vitest config
|
I got it to work using the vs code workspace workaround. You can define your workspace using a file in the root with the name {
"folders": [
{
"path": "apps/webapp",
"vitest.commandLine": "yarn vitest --root apps/webapp"
},
{
"path": "packages/integrations",
"vitest.commandLine": "yarn vitest --root packages/integrations"
}
]
} |
The
|
In nx mono-repository I was able to get this working finally using the vitest.workspace.ts method, and nothing more then the default command line options: Notes:
// <root>/vitest.workspace.ts
import { defineWorkspace } from 'vitest/config'
export default defineWorkspace([
'packages/**/vitest.config.{e2e,unit}.ts',
'packages/**/vitest.config.ts'
]) // <root>/vitest.shared.ts
import { UserConfig } from 'vitest'
import { defaultExclude } from 'vitest/config'
const config: UserConfig = {
globals: true,
environment: 'node',
cache: {
dir: '../../../node_modules/.vitest'
},
include: ['test/**/*.test.ts'],
exclude: defaultExclude
}
export default config // <root>/packages/features/some-vue-feature/vitest.config.ts
import configShared from '../../../vitest.shared'
import { defineConfig, mergeConfig } from 'vitest/config'
import viteConfig from './vite.config'
import path from 'path'
import { UserConfig } from 'vitest'
const config: UserConfig = {
...configShared,
environment: 'jsdom',
setupFiles: ['test/unit/test-setup.ts'],
alias: {
'@/store': path.resolve(__dirname, 'test/unit/__mocks__/store.ts'),
'@ezwebproductions/lib-core': path.resolve(__dirname, '../../lib/core/src/index.ts')
}
}
export default mergeConfig(
viteConfig({ mode: 'test', command: 'build' }),
defineConfig({
test: config
})
) // <root>/packages/lib/core/vitest.config.ts
import { mergeConfig, defineConfig } from 'vitest/config'
import configShared from '../../../vitest.shared'
import viteConfig from './vite.config'
export default mergeConfig(
viteConfig({ command: 'build', mode: 'test' }),
defineConfig({ test: configShared })
) // project.code-workspace
{
"vitest.enable": true,
"vitest.commandLine": "npx vitest",
"vitest.exclude": [
"**/node_modules/**",
"**/dist/**",
"**/cypress/**",
"**/.{idea,git,cache,output,temp}/**",
"packages/commonjs-only-systems/**/*.test.ts"
],
"vitest.include": [
"packages/limit/your/use/case/for/ui/tests/here/**/*.test.ts",
"packages/features/**/*.test.ts",
"packages/lib/idb/**/*.test.ts",
"packages/lib/core/**/*.test.ts"
]
} |
@steven87vt this was massively helpful. By far one of the most helpful comments I've seen on GitHub. Thanks a million for this! |
Describe the bug
Not working properly in monorepo projects. By not working propertyly means vite could not resolve path alias becasue vitest was executed in the wrong user dir which is the root dir (which should be the package/xxx dir where vite.config exists ).
To Reproduce
Run test in monorepo with
resolve.alias
defined invite.config
of sub package.Expected behavior
Working properly in monorepo.
Screenshots
Environment
(Paste info.txt content generated by the example project)
Additional context
The text was updated successfully, but these errors were encountered: