72G*_*2GM 36 karma-jasmine visual-studio-code angular-cli angular
我正在使用Angular CLI和VS代码,但是当我运行测试时,我的spec文件中的所有断点似乎都没有受到影响?
我需要做一些配置吗?
72G*_*2GM 39
其他答案是完全有效的答案,但现在已经使用Angular大约18个月了,我倾向于在浏览器中使用它 - chrome工具!
运行ng测试然后f12并通过webpack上下文找到spec文件.添加断点并刷新,它将触发所述断点.截至截图
And*_*son 16
这对我使用Angular CLI 1.0.*和Windows 7上的Chrome有用.
在你的项目根目录中打开_karma_webpack_
.在pathMapping
添加.vscode/launch.json
后跟随此部分:
{
"type": "chrome",
"request": "attach",
"name": "Unit tests",
"address": "localhost",
"port": 9333,
"sourceMaps": true,
"webRoot": "${workspaceFolder}",
"pathMapping": {
"/_karma_webpack_": "${workspaceFolder}"
}
},
Run Code Online (Sandbox Code Playgroud)
添加配置到karma.conf.js
:
customLaunchers: {
ChromeDebug: {
base: 'Chrome',
flags: [ '--remote-debugging-port=9333' ]
}
}
Run Code Online (Sandbox Code Playgroud)
跑 singleRun: false
等待Chrome浏览器启动.您将在命令行中看到类似的内容:
{
"type": "chrome",
"request": "attach",
"name": "Unit tests",
"address": "localhost",
"port": 9333,
"sourceMaps": true,
"webRoot": "${workspaceFolder}"
},
Run Code Online (Sandbox Code Playgroud)在其中一个,
文件中设置断点.
在Visual Studio Code中选择.vscode/launch.json
debug configuration并按F5("Start Debugging"按钮).
按ng test --browsers ChromeDebug
或刷新Chrome窗口以重新运行测试并点击断点.
您还可以修改package.json并添加新脚本:
01 06 2017 16:07:29.276:INFO [launcher]: Launching browser ChromeDebug with unlimited concurrency
Run Code Online (Sandbox Code Playgroud)
然后下次你想开始.spec.ts
调试就运行:
"test-debug": "ng test --browsers ChromeDebug",
Run Code Online (Sandbox Code Playgroud)
参考文献:
只是添加到其他答案:
ng test
.ng test
从下拉列表中选择。 归档时间: |
|
查看次数: |
25511 次 |
最近记录: |