使用 node-inspector 调试 jasmine-node 测试
有谁知道这是否可能?节点检查器的大部分示例似乎都是为了调试调用的网页。不过,我希望能够调试 jasmine-node 测试。
Does anyone have any idea if this is possible? Most of the sample for node-inspector seemed geared toward debugging an invoked webpage. I'd like to be able to debug jasmine-node tests though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简而言之,只需调试 jasmine-node:
如果您查看 jasmine-node 脚本的源代码,它只是调用 cli.js,我发现我可以调试它脚本就好了。
我想使用节点检查器来调试 CoffeeScript 测试。只需添加
--coffee
开关就可以很好地工作,例如In short, just debug jasmine-node:
If you look at the source of the
jasmine-node
script, it just invokescli.js
, and I found I could debug that script just fine.I wanted to use node-inspector to debug a CoffeeScript test. Just adding the
--coffee
switch worked nicely, e.g.我最终编写了一个名为“toggle”的小实用程序:
您可以将其放入单元测试中,例如:
然后运行测试,例如:node --debug myfile.js debug。如果你运行调试开关,它将等待你除了 ctrl-c 之外的任何操作。 Ctrl-c 退出。您也可以重新运行,这很好。
w0000t。
I ended up writing a little util called toggle:
You can drop it into your unit tests like:
And then run your tests like: node --debug myfile.js debug. If you run debug toggle will wait until you anything but ctrl-c. Ctrl-c exits. You can also rerun, which is nice.
w0000t.
我未经教育的猜测是,您需要修补 jasmine,我相信它在运行测试时会生成一个新的节点进程或其他进程,并且这些新进程需要启用调试。
我有类似的愿望并设法使用 Eclipse 作为调试器让expressso工作:
http://groups.google.com/group/nodejs/browse_thread/thread/af35b025eb801f43
…但我意识到:如果我需要单步执行代码来理解它,我可能需要重构代码(可能是更可测试),或者将我的测试分解为更小的单元。
您的测试就是您的调试器。
My uneducated guess is that you'd need to patch jasmine, I believe it spawns a new node process or something when running tests, and these new processes would need to be debug-enabled.
I had a similar desire and managed to get expressso working using Eclipse as a debugger:
http://groups.google.com/group/nodejs/browse_thread/thread/af35b025eb801f43
…but I realised: if I needed to step through my code to understand it, I probably need to refactor the code (probably to be more testable), or break my tests up into smaller units.
Your tests is your debugger.