Skip to content

Instantly share code, notes, and snippets.

@andykingking
Created March 23, 2017 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andykingking/f31b64286d851f3431035003aa39279f to your computer and use it in GitHub Desktop.
Save andykingking/f31b64286d851f3431035003aa39279f to your computer and use it in GitHub Desktop.
Debugging with Jest and VSCode

Debugging with Jest and VSCode

Assumptions

  • Your jest config is named jest.json.
  • You use babel.
  • You build to build.

Debugging

Add the following code as a debugging configuration.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Tests",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
            "stopOnEntry": false,
            "args": [
              "--config",
              "jest.json",
              "--runInBand"
            ],
            "cwd": "${workspaceRoot}",
            "preLaunchTask": null,
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "console": "internalConsole",
            "sourceMaps": true,
            "outFiles": [
              "${workspaceRoot}/build/**/*.js"
            ]
        }
    ]
}

Make sure the following lines are in your .babelrc.

  ...
  "sourceMaps": "inline",
  "retainLines": true,
  ...

Set a breakpoint and debug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment