Debugging mocha.js remote test using node inspector?

I have a test file on a remote machine and I want to go through it with a node-inspector . So, on the remote machine ( Vagrantfile ):

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

Then on my dev machine, I open Canary and go to:

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

However, I canโ€™t debug my test, because the debugger breaks into the first line in node_modules/mocha/bin/_mocha , and the test file does not appear on the Sources tab

enter image description here

I tried to set a breakpoint inside _mocha, on line 398 :

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

But when I try to โ€œenterโ€ to see how the run function is executed, it does not enter. I can see the output in the console, so it runs. If I set a breakpoint directly in the run function , it will not be broken there.

In addition, the test file never appears on the Sources tab, so I cannot set breakpoints in it. I also tried adding a debugger statement to it, but it still doesn't crash there.

How can I make node -inspector show a test file and execute it?

 node v0.12.0 node-inspector v0.10.0 mocha v2.2.4 
+5
source share
2 answers

There are actually 2 problems:

  • breakpoints not respected
  • test files are not displayed

The first issue was fixed in the recently released node-inspector@v0.10.1 . This way, breakpoints will be respected anywhere.

There is a second problem. As @JMM said, the list of files on the Sources tab is dynamic, and the test files will not appear there when the process is interrupted. What I ended up with is setting a breakpoint just before running the test function in mocha/lib/runnable.js#266 on this line:

 var result = fn.call(ctx); 

fn is a test function. After you enter it, the test file will appear on the Sources tab, and the debugger cursor will be in the first line of the test function.

+1
source

I often come across this, and I donโ€™t know if there is a better solution (if there is, I will be glad to hear it), but I believe that I should let the debugger go to the point where it becomes after learning about additional files that I want debug. Without seeing more of my code, I canโ€™t give more specific suggestions on where to go, but try to find out where the test files will be loaded into the source files that are available and will move there. It will gradually add more files to the Sources panel as the code runs.

+1
source

All Articles