VSCode debugging with custom Jest configurations

Mar 1, 2018

Sunny Golovine

About a week ago I was sitting at my desk at work trying to figure out why one of my Jest tests were failing. After trying and failing to fix the test, I realized I needed to debug the Jest test….

Go to Google, “debugging jest tests” then “debugging jest tests in vscode”. One Medium article later, I had a pretty good idea of how to get it setup. Added the launch configuration, hit the button and almost immediately hit my first snag, my company uses a jest configuration and whatever came out of the box with jest wasn’t going to cut it.

More time than I am willing to admit went into searching for a solution on how to use a custom jest configuration with vscode. In the end, this is the article I wish I had found when I was searching for a solution.

The solution is rather simple

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Jest All",
      "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      "args": ["--config", "<your jest configuration file>", "--runInBand"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "sourceMaps": true
    }
  ]
}

When adding the launch configuration, add this one instead of the default one provided and replace <your jest configuration file> with its proper path.

Hope this article helps.


More Posts