![](/img/trans.png)
[英]How to run specific tests using Jasmine and Visual studio code?
[英]How to debug Jasmine tests run from Grunt in Visual Studio Code?
我的單元測試是通過Grunt使用Karma / Jasmine運行的。 我跑的時候
grunt test
測試從命令行執行。
在Visual Studio Code中打開項目時,我可以使用Tasks: Run Test Task
運行相同的命令。 VSCode使用test
參數執行Grunt並顯示輸出。
在這種情況下,如何調試VSCode運行的測試用例? 當我按F5時 ,將打開launch.json
模板文件。 我需要為program
, args
等提供什么來啟動/調試由grunt test
運行的相同grunt test
?
我嘗試過以下方法:
program
: /usr/local/bin/grunt
args
: ["test"]
這成功啟動了Grunt進程並執行了測試,但它並沒有在我的測試代碼中的斷點處停止。
除此之外,它會在幾秒鍾后關閉(或崩潰)整個VSCode進程。 不確定這是VSCode中的錯誤還是上述運行配置的結果。
我不認為你現在可以做一些像node --debug-brk grunt test
這樣的測試將啟動茉莉花測試 - 因為jasmine會在沒有調試標志的情況下調用這些spec文件上的節點。 我試過這個,這就是我得到的:
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的調試器將查看3691而46307沒有被任何東西檢查 - 我不知道如何告訴vscode也聽這個端口。
Soooo我最終做的是按照這里發布的答案: 使用node-inspector調試jasmine-node測試
基本上我的vscode launch.json
包含一個如下launch.json
的配置:
{
"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"
]
}
希望有所幫助。
這個啟動配置適用於VS Code 0.10.2:
{
"name": "grunt",
"type": "node",
"request": "launch",
"program": "/usr/local/bin/grunt",
"args": ["test"],
"stopOnEntry": false
}
在我的“測試”任務中設置斷點使VS Code調試器停在那里。 我不得不在本地安裝grunt(在我有Gruntfile的文件夾中)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.