如何debugging从Visual Studio代码中的Grunt运行茉莉花testing?

我的unit testing是通过Grunt使用Karma / Jasmine运行的。 当我跑步

grunt test 

testing从命令行执行。

在Visual Studio代码中打开项目时,可以使用“ Tasks: Run Test Task相同的命令。 VSCode使用test参数执行Grunt并显示输出。

在这种情况下,如何debugging由VSCode运行的testing用例? 当我按下F5时launch.json模板文件被打开。 我需要提供什么programargs等来启动/debugging通过grunt test运行相同的grunt test

我已经尝试了以下内容:

  • program/usr/local/bin/grunt
  • args["test"]

这成功地启动了Grunt进程并且执行了testing,但是它并不停止在我的testing代码的断点处。

除此之外,它会在几秒钟后closures(或崩溃)整个VSCode进程。 不知道这是VSCode中的错误还是上述运行configuration的结果。

VS Code 0.10.2中这个启动configuration适用于我:

 { "name": "grunt", "type": "node", "request": "launch", "program": "/usr/local/bin/grunt", "args": ["test"], "stopOnEntry": false } 

在我的“testing”任务中设置一个断点,VS代码debugging器停在那里。 我不得不在本地安装grunt(在我有Gruntfile的文件夹中)。

我不认为你现在可以做类似node --debug-brk grunt test ,其中testing将启动茉莉花testing – 因为茉莉花将调用这些spec文件上的节点,而没有debugging标志。 我试了这个,这是我得到的:

 node --debug-brk=3691 --nolazy ../../../usr/local/bin/grunt kftest --schema=9.2.1 --dbtype=sqlite --target=builder/properties --spec=test/builder/properties/properties-spec.js Debugger listening on port 3691 Running "kftest" task >> going to run with spec: test/builder/properties/properties-spec.js >> command: node --debug-brk=46307 /Users/computername/project/node_modules/jasmine-node/lib/jasmine-node/cli.js test/builder/properties/properties-spec.js Running "shell:kftest" (shell) task Debugger listening on port 46307 

这是不是太有用,因为现在vscode的debugging器将在3691而46307没有被任何检查 – 我不知道如何告诉vscode也听该端口。

所以我最终做的是按照这里发布的答案: debugging节点检查器的茉莉节点testing

基本上我的vscode launch.json包含一个看起来像这样的configuration:

 { "name": "Jasmine-Node Debugging", "cwd": "${workspaceRoot}", "program": "${workspaceRoot}/node_modules/jasmine-node/lib/jasmine-node/cli.js", "request": "launch", "type": "node", "args": [ "test/builder/properties/properties-spec.js" ] } 

希望有所帮助。