[英]Typescript, tests and debugging in VS Code
I am new to angular2 and typescript and have made a simple application which was generated with the angular CLI. 我是angular2和Typescript的新手,并做了一个简单的应用程序,该应用程序是用angular CLI生成的。 Before I go on, I have to say that there is a gap in my understanding of what happens between seeing typescript code in VS Code and a running app in the browser. 在继续之前,我不得不说,我对在VS Code中查看打字稿代码与在浏览器中运行应用程序之间的理解存在差距。
In previous editors, I was used to seeing .js files generated and made sense of my running application as a web page with those generated files. 在以前的编辑器中,我习惯于查看生成的.js文件,并且将正在运行的应用程序理解为包含这些生成的文件的网页。 But when one runs ng serve
there are no .js files anywhere and the app still runs in the browser. 但是,当运行ng serve
,任何地方都没有.js文件,并且该应用仍在浏览器中运行。 The first thing I want to know is how that happens- I thought typescript was not readable by browsers. 我想知道的第一件事是如何发生的-我认为浏览器无法读取打字稿。
Secondly, I am having trouble debugging unit tests in the Karma test runner using VS Code. 其次,我在使用VS Code在Karma测试运行器中调试单元测试时遇到了麻烦。 I am able to debug the application itself, I am able to attach the debugger to the Karma instance, but when I put a breakpoint in my test I get the error breakpoint ignored because generated code not found (source map problem?)
. 我可以调试应用程序本身,也可以将调试器附加到Karma实例,但是当我在测试中放置断点时, breakpoint ignored because generated code not found (source map problem?)
导致错误breakpoint ignored because generated code not found (source map problem?)
。 For reference this is my launch.json
: 供参考,这是我的launch.json
:
{
"type": "chrome",
"request": "attach",
"name": "Attach Karma Chrome",
"address": "127.0.0.1",
"port": 9333,
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
}
and my karma.conf.js
contains 我的karma.conf.js
包含
browsers: ['ChromeDebugging'],
customLaunchers : {
ChromeDebugging: {
base: 'Chrome',
flags: ['--remote-debugging-port=9333']
}
},
EDIT: This is the full karma.conf.js 编辑:这是完整的karma.conf.js
try this 尝试这个
{
"type": "chrome",
"request": "attach",
"name": "Attach Karma Chrome",
"address": "127.0.0.1",
"port": 9333,
"sourceMaps": true,
"webRoot": "${workspaceRoot}/test"
}
我决定使用有角种子存储库在浏览器中调试测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.