【问题标题】:Debug Jest with Electron using VS Code使用 VS Code 使用 Electron 调试 Jest
【发布时间】:2018-08-20 19:42:05
【问题描述】:

当我使用 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 命令是正确的,但是 VSCode 添加的--debug-brk --inspect 选项似乎与 Jest 混淆了。

【问题讨论】:

  • 你有没有想过这个问题?我自己也遇到了同样的问题
  • 不抱歉,我没有在这个项目中使用调试器。不过,使用 Node 进行调试通常就足够了,除了特定的 Electron 代码。

标签: debugging visual-studio-code jestjs electron vscode-debugger


【解决方案1】:

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

{
  "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-19
    • 2018-05-13
    • 2021-01-07
    • 2020-08-22
    • 2019-05-30
    • 2015-10-04
    • 2015-10-11
    • 2017-01-27
    • 2020-12-16
    相关资源
    最近更新 更多