-
Notifications
You must be signed in to change notification settings - Fork 290
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
Support monorepos #129
Comments
As you can customise the command used to trigger jest ( |
I have tried adding a script to the root package.json with all projects specified with |
It does support monorepos, we have it working here for one of our projects using lerna. Jest resides at the root of your monorepo, correct? We added this to our
|
we also have a lot of problems with vscode-jest for our lerna managed monorepo. we would like to have the root vscode workspace able to watch for all file changes in the packages, report test failures on the problems inspector and update test decorators just like in the single project case. We have tried both approaches:
To further complicate the issue, our packages are not uniformed, i.e. there are typescript, javascript, react and react-native, therefore the default settings, which only look for js(x) patterns, doesn't work for us. approach 2 is working, as far as running jest with --watch, but vscode-jest simply can't parse the result and update the editor accordingly. approach 1, as mentioned above, is not working with or without vscode-jest. Maybe we are missing something obvious, @ls-guillaume-lambert, do you mind sharing with us how you get it to work? Thx. |
We have a much simpler setup with only React components, no TypeScript or any extra layer. The approach I mentioned in #129 (comment) works for us, nothing else is in place other than those |
thanks @ls-guillaume-lambert, so looks like you just run jest on the root project and has it watch and run for all tests below with the same jest config file. Yes that should work if all the tests are "uniform", i.e. same preset, rules, patterns etc. However, many monorepo projects are cross-platform and languages, it will be nice for vscode-jest to support a true "multi-jest" style monorepo... |
Indeed, we are using the same preset/rules/patterns for all our packages. Best of luck with your setup 👍 |
ok, finally get the jest to work for our environment via command line. vscode-jest is still having quite a few problems:
I will submit PR to address some of these issues... |
^ These are great ideas 👍 |
@connectdotz can you please share with me your setup? i'm having the same issue |
@Bnaya sorry for the delay, basically you need a superset jest config with instructions for all of your packages. Here is my jest config on the root/project level that will run jest for all packages including react-native package:
and my tsconfig.json for completion:
hope it help... good luck. |
@connectdotz Thanks! |
@Bnaya that is correct |
Would just like to add my name to the list of people who would love this feature. We have a monorepo and currently the only way for us to debug tests is to have a different instance of vs code open for each package. |
A note that while this issue is about mono-repos the |
I'll help you build it if you can help with an example repo and Jest setup @wldcordeiro. |
@seanpoulter I don't have a repo on hand but I think we could make one with this as a starting point. https://gist.github.com/wldcordeiro/6dc2eb97a26a52d548ed4aa86f2fc5c0 I pretty much lifted those as is from a real project. |
Sometimes I lose a state in |
Those symptoms sound familiar @XBeg9. That used to happen when Jest ran in watch mode and there were no changes. I'd suggest running the extension locally and setting a conditional breakpoint to fire when we're getting the data back from Jest and it's empty. |
Sorry, not sure I understand this :) |
This issue is pretty cold but as a new monorepo and vscode-jest user, this problem became evident fairly quick with no immediate solution. I really want to avoid extra files in the repo as a workaround. |
Speaking for myself here, it's not clear that "we the maintainers" have much bandwidth these days. If you're motivated to move this forward @jsphstls, we could probably nudge @connectdotz and @ls-guillaume-lambert to weigh in on their experience and how we'd need to update the extension. From what I can gather from skimming the issue, the "solution" was to add extra setup per project. |
What's about to do something like that? (I didn't look at your code yet, but this would be an idea to get the root folder for the current active file)
|
for people with monorepo projects, multi-root support has finally arrived, feel free to give it a try: 3.0.0-preRelease ... |
The workspace feature didn't help in my case. I have tests that contain JSX and are written in TypeScript, and here are two "manual" examples of how to possibly run the tests: ✅ This works:
🚫 This doesn't work:
The extension probably invokes the test close to the second example as I get the same, well-known error:
|
Same – the workspace feature doesn't help me either. My only workspace root is the root of my monorepo. My individual packages are just in a If I set up an instance of vscode with my package as the workspace root, vscode-jest can't find Jest, because it's installed above the individual package. |
this plugin does some simple "guess" of how to run your tests with jest, while it is right for most simple cases, it most likely will not be able to cover the more sophisticated use cases, and that is where for your workspace folders (the directory under "packages" for most monorepo setup), you might need to customize the For example, if you have a React package, most likely you are running
As long as you can run your tests from your package, you can construct this plug in to do the same via the custom settings provided, such as |
I can confirm that the solution provided by @connectdotz does work for a collection of Bit of
Bit of
|
GoalMy goal is to get this vscode-jest "Debug" button to work with yarn workspaces and VS Code workspaces.
|
@amoshydra You saved my day !!! |
The activationEvents in this extension don't support monorepos: https://github.com/jest-community/vscode-jest/blob/master/package.json#L32-L38
should instead be
this should be a backwards compatible change as it will still work for files at the top level. Whilst on the subject, I'm not 100% sure |
For those digging around looking for the actual solution to this, it is documented here How to use the extension with monorepo projects? |
@davidlbudiman sorry for the late reply, that feature is in v5 pre-release, feel free to give it a spin and let us know how it works for you. Thanks. |
It would be great if this plugin supported monorepos. Either by passing the
--projects
option to jest or by starting a jest process for every subproject (folder withpackage.json
file in it). In the case of multiple Jest processes the current setting paths should be relative from each subproject.The text was updated successfully, but these errors were encountered: