如何在VS Code中为Vue Mocha单元测试配置调试?

时间:2019-08-09 13:03:09

标签: visual-studio-code vue-cli-3 vscode-debugger mocha-webpack

我已经设法启动调试器,但是看起来VS Code看不到源图。

当我添加debugger JS语句时,它会在webpack生成的文件main.js中中断(该事件在文件系统中不存在),但是使用它很痛苦。

我有下一个设置:

package.json:

    "scripts": {
        "test:debug": "node --inspect-brk ./node_modules/@vue/cli-service/bin/vue-cli-service.js test:unit"
    }

launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug unit tests",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "program": "${workspaceFolder}/node_modules/@vue/cli-service/bin/vue-cli-service.js",
      "args": [
        "test:unit",
        "--inspect-brk"
      ],
      "port": 9229
    }
  ]
}

我尝试了多种方法来指定源地图,但没有帮助。

有人能正常工作吗?

1 个答案:

答案 0 :(得分:2)

这就是我的工作,断点在TS / JS和单元测试内部均有效。使用“ @ vue / cli-service”:“ ^ 4.1.1”和“ @ vue / test-utils”:“ ^ 1.0.0-beta.30”。

launch.json

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Mocha Tests",
      "runtimeExecutable": "npm",
      "runtimeArgs": ["run-script", "test:debug"],
      "port": 9229,
    }
  ]
}

package.json

"test:debug": "vue-cli-service test:unit --inspect-brk",

在测试代码中添加一行“调试器”以开始检查,然后将在vscode中打断点。否则,将--watch添加到“ test:debug”,然后您的断点将命中,而无需调试器行,如下所示:

"test:debug": "vue-cli-service test:unit --inspect-brk --watch",
相关问题