VSCode中调试Jest

在vscode中进行调试配置时,需要注意一下node版本,虽然在v6.12之后已经可以使用inspect,但如果protocol设置为inspector,会发现断点无法触发。

解决方式很简单,将protocol切换为legacy,同时调整相应的端口设置即可,如下所示。

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Jest Tests",
      "protocol": "legacy",
      "port":5858,
      "type": "node",
      "request": "launch",
      "sourceMaps": true,
      "runtimeArgs": [
        "--debug-brk",
        "${workspaceRoot}/node_modules/.bin/jest",
        "-i"
      ],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}
Show Comments

Get the latest posts delivered right to your inbox.