VS Code debugger configuration for Jest
In this post I share my VS Code debugger configuration to debug Jest tests. This configuration will helps you debug a single Jest file simply by opening it and hitting F5.
Before we had over the configuration, make sure you have Jest installed locally:
npm install jest --save-dev
To easily debug Jest tests using the VS Code debugger create a folder .vscode
in the root directory of your project. Then, create file name launch.json
and copy and paste the following. If you already have a launch.json
file simply copy and paste the object in the configurations array to the configurations array in your launch.json
.
A couple of things worth highlighting:
runtimeArgs
: Here we specify the configuration we want to pass to Jest. Noteworthy is the addition of the argument"${fileBaseName}"
. This makes sure that Jest only runs the file that is currently open. If you delete this runtime argument Jest would test all files after starting the debugger. This is generally not what you want.skipFiles
: makes sure that while you step through your functions you don’t end up in Node’s files or dependencies. If you’re debugging and you like to step through these files delete"<node_internals>/**"
or"**/node_modules/**"
or both from the array.internalConsoleOptions
: I like the debugger console to open once I launch the debugger. However, if you don’t like that, you can simple set this setting to"neverOpen"
.
Let me know if this solution helped you in the comments or by clapping!