简体   繁体   English

使用node-inspector调试远程mocha.js测试?

[英]Debug remote mocha.js test with node-inspector?

I have a test file on a remote machine and I want to walk through it with node-inspector . 我在远程计算机上有一个测试文件,我想通过node-inspector遍历它。 So, on the remote machine ( Vagrantfile ): 所以,在远程机器上( Vagrantfile ):

node-inspector &
mocha --debug-brk foo.test.js

Then, on my dev machine I open Canary and go to: 然后,在我的开发机器上,我打开Canary并转到:

http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858

However, I'm not able to debug my test, since the debugger will break at the first line in node_modules/mocha/bin/_mocha , and my test file isn't visible in the Sources tab : 但是,我无法调试我的测试,因为调试器将在node_modules/mocha/bin/_mocha的第一行node_modules/mocha/bin/_mocha ,并且我的测试文件在Sources选项卡中不可见

在此输入图像描述

I tried setting a breakpoint inside _mocha, on line 398 : 我尝试在第398行的 _mocha中设置一个断点:

runner = mocha.run(program.exit ? exit : exitLater);

But when I try to 'step into', to see the run function execute, it doesn't step in. I can see output in the console, so it does execute though. 但是当我试图'进入'时,看到run函数执行,它没有介入。我可以在控制台中看到输出,所以它确实执行。 If I set a breakpoint directly in the run function , it won't break there. 如果我run函数中直接设置断点,它就不会在那里中断。

Also, the test file never appears in the "Sources" tab so I can't set breakpoints in it. 此外, 测试文件永远不会出现在“源”选项卡中,因此我无法在其中设置断点。 I also tried adding a debugger statement to it but it still doesn't break there. 我也尝试添加一个debugger语句,但它仍然没有在那里打破。

How can I make node-inspector show the test file, and step through it ? 如何让node-inspector显示测试文件并逐步完成?

node v0.12.0
node-inspector v0.10.0
mocha v2.2.4

I frequently run into this, and I don't know if there's a better solution (if there is I'll be glad to hear it), but I find I have to let the debugger advance to a point where it becomes aware of the additional files I want to debug. 我经常遇到这种情况,我不知道是否有更好的解决方案(如果有我会很高兴听到它),但我发现我必须让调试器进入一个让它意识到我想调试的其他文件。 Without seeing more of your code I can't give a more specific suggestion about where to advance to, but try to figure out where the test files will be loaded in the source files that are available and advance to there. 在没有看到更多代码的情况下,我无法提供有关前进位置的更具体的建议,但是尝试找出测试文件将在可用的源文件中加载到哪里并前进到那里。 It'll gradually add more files to the Sources panel as code runs. 当代码运行时,它会逐渐向Sources面板添加更多文件。

There are actually 2 problems: 实际上有两个问题:

  1. breakpoints not respected 断点没有得到尊重
  2. test files not visible 测试文件不可见

The first problem was fixed in the recently released node-inspector@v0.10.1 . 第一个问题在最近发布的node-inspector@v0.10.1得到修复。 So, breakpoints will be respected anywhere. 因此,断点将在任何地方得到尊重。

There is still the second issue. 还有第二个问题。 As @JMM said, the list of files in the 'Sources' tab is dynamic, and test files won't appear there when the process breaks. 正如@JMM所说,'Sources'选项卡中的文件列表是动态的,当进程中断时,测试文件不会出现在那里。 What I ended up doing is setting a breakpoint just before the test function is run, in mocha/lib/runnable.js#266 , on this line: 我最终做的是在测试函数运行之前设置一个断点,在mocha/lib/runnable.js#266 ,在这一行:

var result = fn.call(ctx);

fn is the test function. fn是测试功能。 Once you step into it, the test file will appear in the Sources tab and the debugger's cursor will be on the first line of the test function. 一旦你进入它,测试文件将出现在Sources选项卡中,调试器的光标将在测试函数的第一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM