Open mikecousins opened 1 year ago
I would also appreciate this docs update. I am struggling with making vitest work with turborepo
This does seem like a useful example, we're open to contributions, but not sure when we'll be able to create one ourselves!
is there any hint or heads up on how can we consolidate vitest workspaces and turborepo? my current work around is to opt-out the test script from being running using turbo and run it using normal vitest command. this help me to get consolidated coverage.
I also would love to see some guidance. We are currently doing the same as @Nilegfx. For Vitest workspace to work, one needs to define the vitest script in the root package.json. I was able to run it from the root with turborepo like this:
// root package.json
"scripts": {
// invoke vitest with configured workspace
"vi:unit": "vitest run --coverage",
// run said script with turborepo
"test:unit:turbo": "turbo run vi:unit --filter=//",
}
// turbo.json
{
"pipeline": {
"//#vi:unit": {
"dependsOn": [],
"outputs": []
},
}
}
But this way, turborepo can't be used with its full potential. First run w/o cache hit -> all tests defined in vitest workspace run (2min on our side). Run command again -> full turbo. Change some test in a package and run task again -> all tests run again. I would love to have only the tests re-run from the package the test was changed.
I think the only way to benefit from turbo repo here is to not use Vitest workspace feature and instead have a test script in each package that runs vitest itself. So, one could define a turbo script in the root package.json like this to run all scripts with same name across packages: "test:unit": "turbo run test:unit",
.
Combined coverage is gone with this approach. Maybe each package can output its own coverage report and then manually stich them together eg. with istanbul-merge.
Do you have any updates on this? As @dsvgl mentioned, if we choose to use 'turbo' way, we can't make a combined coverage report. If we choose 'vitest native' solution (with vitest.workspace.json
, Every test will run again.
In my project, I had to choose 'vitest' one since I needed combined coverage. Either way, turborepo should list both options or at least warn users of current drawbacks and workarounds on the doc.
Which project is this feature idea for?
Turborepo
Describe the feature you'd like to request
In
0.30.0
vitest has added first class support for monorepos. https://twitter.com/vitest_dev/status/1645071039003590656The syntax is documented here: https://vitest.dev/guide/workspace.html
The current documentation doesn't reflect the new syntax.
Describe the solution you'd like
It would be great to update the documentation with best practices for how to define the workspace file, migrate to the new project config files, run tests and report shared coverage, etc.
Describe alternatives you've considered
None