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

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

我有一个 Jest 测试套件,我想使用 VS Code 交互式调试器对其进行调试。这对于普通的 NodeJS 程序(launch.json 中的"program": "foo.js")工作正常。但是测试套件 (foo.test.js) 不是一个独立的程序,它必须是来自 Jest 的 运行。

有办法实现吗?

具体代码在这里:https://gitlab.com/stevage/guess-projection

调试标准 Jest 测试

This doc in Microsoft's vscode-recipies GitHub 存储库描述了如何设置 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 文档的 create-react-app then the configuration is a little different since Jest is not launched directly and is described in this section 引导的 React 应用程序。