如何在VS Code中交互式调试NodeJS测试套件?

时间:2018-11-27 21:15:58

标签: unit-testing debugging visual-studio-code jestjs vscode-debugger

我有一个Jest测试套件,我想使用VS Code交互式调试器进行调试。对于正常的NodeJS程序("program": "foo.js"中的launch.json)来说,这很好用。但是测试套件(foo.test.js)并不是一个自包含的程序,它必须从Jest运行。

有没有办法做到这一点?

特定代码在这里:https://gitlab.com/stevage/guess-projection

1 个答案:

答案 0 :(得分:2)

调试标准的Jest测试

微软的This doc GitHub存储库中的

vscode-recipies描述了如何设置VS Code来调试标准的Jest测试。

launch.json看起来像这样:

{
  "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",
      }
    }
  ]
}

调试create-react-app Jest测试

如果您的应用程序是使用create-react-app引导的React应用程序,则配置会有所不同,因为Jest不会直接启动,并且在create-react-app文档的this section中进行了描述。