4

I have a test file on a remote machine and I want to walk through it with 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'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:

enter image description here

I tried setting a breakpoint inside _mocha, on line 398:

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. If I set a breakpoint directly in the run function, it won't break there.

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.

How can I make node-inspector show the test file, and step through it ?

node v0.12.0
node-inspector v0.10.0
mocha v2.2.4
4
  • So, how are you accessing the remote machine from your dev machine via http://127.0.0.1? Commented May 7, 2015 at 14:03
  • @JMM ports 5858 and 8080 on the remote are forwarded to local 5858 and 8080 Commented May 7, 2015 at 16:53
  • Ah, ok, thank you. Would it be possible for you to create a minimal reproduction of this issue that I could clone from GitHub or somewhere? Commented May 7, 2015 at 17:04
  • 1
    @JMM I made a repo wich reproduces the issue: github.com/mrotaru/node-inspector-test It's a Vagrant box so you can simply vagrant up to have everything ready Commented May 7, 2015 at 22:41

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

will give it a shot tomorrow; I didn't know that the list of files is dynamic.
hm, I must be doing something wrong because I never see the test file in the Sources tab; question updated with more details.
1

There are actually 2 problems:

  1. breakpoints not respected
  2. test files not visible

The first problem was fixed in the recently released [email protected]. 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. 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:

var result = fn.call(ctx);

fn is the test function. 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.