1

当我使用 Electron 时,我无法在 VS Code 中调试我的 Jest 测试。我的测试应该使用 Electron,而不是 Node(由于使用了本机模块)。

{
  "name": "Jest Unit Tests",
  "type": "node",
  "request": "launch",
  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
  "program": "${workspaceRoot}/node_modules/.bin/jest",
  "windows": {
    "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
  },
  "env": {
    "ELECTRON_RUN_AS_NODE": "1",
    "NODE_ENV": "test",
    "BABEL_DISABLE_CACHE": "1"
  },
  "args": [
    "-i",
    "--verbose",
    "-c test/config/jest.unit.json"
  ],
  "internalConsoleOptions": "openOnSessionStart"
},

它基于用于使用 Node 调试 Jest 的常用配置(工作正常),但我无法让它与 Electron 一起使用。Jest 命令是正确的,但是--debug-brk --inspectVSCode 添加的选项似乎与 Jest 混淆了。

4

1 回答 1

0

根据您的问题,我能够使我的配置正常工作。谢谢!

{
  "type": "node",
  "request": "launch",
  "name": "Debug Current Jest File:Electron",
  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
  "program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
  "args": [
    "--verbose",
    "-i",
    "--no-cache",
    "--testPathPattern",
    "${fileBasename}",
    "--coverage",
    "false"
  ],
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "env": {
    "ELECTRON_RUN_AS_NODE": "true"
  }
}
于 2021-12-12T15:54:31.603 回答