在 VS Code 中调试 Lerna 项目的 Jest 测试

Nic*_*son 3 jestjs visual-studio-code lerna

我想在 VS 代码中为使用 Lerna 的项目调试特定的 Jest 测试,因此有多个文件夹,每个文件夹都有自己的 node_modules 文件夹。在这个答案的帮助下,我得到了以下 launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Jest watch",
      "program": "${workspaceRoot}/my/specific/module/node_modules/jest/bin/jest.js",
      "args": ["--verbose", "-i", "--no-cache", "--watchAll"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "cwd": "${workspaceFolder}/my/specific/module"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

问题是我必须将模块的特定路径放入启动配置中,因此每次我想调试其他内容时都必须更改它。

有一个更好的方法吗?也许使用在资源管理器中选择的文件夹?也许有某种方法可以通过右键单击测试文件来启动调试?

Nic*_*son 5

非常感谢dlac的想法,我现在有了一个有效的启动配置:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Jest watch",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": ["--verbose", "-i", "--no-cache", "--watchAll"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "windows": {
        "program": "${workspaceFolder}/node_modules/jest/bin/jest"
      },
      "cwd": "${fileDirname}"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)