How to interactively debug a NodeJS test suite in VS Code?

℡╲_俬逩灬. 提交于 2019-12-11 02:03:29

问题


I have a Jest test suite that I would like to debug using the VS Code interactive debugger. That works fine for normal NodeJS programs ("program": "foo.js" in launch.json). But the test suite (foo.test.js) isn't a self-contained program, it has to be run from Jest.

Is there a way to achieve this?

The particular code is here: https://gitlab.com/stevage/guess-projection


回答1:


Debugging standard Jest tests

This doc in Microsoft's vscode-recipies GitHub repo describes how to set up VS Code for debugging standard Jest tests.

The launch.json looks like this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Jest All",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": ["--runInBand"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "windows": {
        "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      }
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Jest Current File",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": ["${relativeFile}"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "windows": {
        "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      }
    }
  ]
}

Debugging create-react-app Jest tests

If your application is a React app bootstrapped with create-react-app then the configuration is a little different since Jest is not launched directly and is described in this section of the create-react-app docs.



来源:https://stackoverflow.com/questions/53508251/how-to-interactively-debug-a-nodejs-test-suite-in-vs-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!