Using with Yarn workspaces
See original GitHub issueIt’s great that vscode-jest
now supports VS Code’s Workspaces.
The problem is, the way VS Code Workspaces currently works is, one has to define each of the services in one’s monorepo as a VS Code workspace.
It’s a pretty tedious process for a project with 15+ services, and counting…
It’s obviously not vscode-jest
’s fault, but I think there might be a rather simple way to support running jest in the right monorepo service without having to configure VS Code for Workspaces.
There are two key aspects to vscode-jest
:
- Running all tests (+watch mode)
- Debugging a single test
1. Running all tests
For running all tests, I was able to run all my services tests, each with each own jest configuration, without having to add define each as workspace.
If you’re using Yarn Workspaces (or Lerna), all I had to do is change the run configuration like so:
"jest.pathToJest": "yarn workspaces run test"
That’s it!
Running this will make Yarn run yarn test
in each of its workspaces, running jest
all tests for services.
So I think that part just works out of the box.
Here’s what needs tweaking to work -
2. Debugging a single test
OK so the idea here is similar, run the right Yarn workspace for the file we’re trying to debug:
// launch.json
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"runtimeArgs": ["workspace","${command:extension.yarnWorkspaceName}", "run", "test"], // ${yarnWorkspaceName} is what we're missing
"args": [
"--runInBand"
],
"runtimeExecutable": "yarn" // ...along with this one,
// will run each Yarn workspace test script
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
}
]
My initial I thought was, maybe we can have vscode-jest
resolve that variable workspace via a command that would be added?
Would love your ideas here @connectdotz , wether that’s an approach that’s seems valid to you, or possibly help me think of alternatives? If you think this might be a good way to go I can have a look at implementing it in a PR.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:12
Top GitHub Comments
I’ve managed to run debug with some help when running the process…
The issue I see here is that the runner will run the tests from the workspace root dir thus skipping any existing configuration specific for the project the file in context belongs to.
So, instead of running jest, I run a script and I send the ${fileDirname} to it so I can locate the proper configuration file and point to it and then I pass it on to jest…
tools/vscode-jest-tests/index.js (the script):
This is simple, find the nearest jest configuration and make jest use it…
Works perfectly for me (monorepo, learn, yarn workspaces (1.2x))
@tettoffensive here’s what works for us:
Where