Vscode Turborepo Jest Debugging
Turborepo is a great tool for managing monorepos, but it's a lot of configuration.
One common workflow for debugging tests is to use the VSCode debugger to attach to the test runner.
All available documentation online assumes that jest
is installed at the root of the project.
This goes against the default recommendations of turborepo
which suggests to install and configure jest
in each package.
The following is what they all recommend.
Here we use the jest
package in the root of the project.
VSCode provides a way to match the root of the vscode project, but no way to match the current monorepo package.
This is a problem because we could be on different versions of jest
in different packages and have wildly different configurations.
To fix this we can write our own program
that will find the closes package dir and instead run tests from there.
Now all we need to do is update the program
in the launch.json
file.
Now when we try to debug a test it will run from the closest package dir, using the jest
executable for the package as well as it's unique configuration.