Mocha debugging



I was trying to debug a Mocha script and I’m running into two issues:

  • The first issue is that if I set the break point inside the “it” statement, it’s not stopping in the IDE and instead puts a message in the editor that says, “Debugger listening on port 5858”. If I then add a watch expression the Debugger tab will have “Debug Session Ended”. Any watch expressions that existed beforehand have “ReferenceError: somevar is not defined”
  • The second issue is that if I put the break point at the closure of the “it” statement, then it will pause correctly and the IDE updates, but my watch expressions still have “ReferenceError: somevar is not defined”

What doesn’t add up is my control was var debuggertest = "testing123". In my head, that should show up in at least one of the two cases above.

I also tried setting the Runner to Mocha and set the Command to “test/sometest.js”, and it would pause correctly in the IDE at the closure of the “it” block, but if in the “it” block then just runs without stopping and finishes with “Process exited with code: 0”.

Am I doing something wrong, or is this because it’s still experimental? I was hoping to get at the variables in the “it” blocks without console.logging them.

UPDATE: It’s actually in the “request” (supertest) block where it’s not pausing. I added some code after it, but in the “it” block and it will pause correctly and show the variable I set there. I may be using supertest wrong.

FIGURED IT OUT: The request was an asynchronous supertest request. I had forgotten to pass in “done”, so I guess the IDE didn’t know what to do with it. Now that the async block is correct, the IDE is breaking inside at “done()” and I can see the variable contents without issue.


Hey @ergose :slightly_smiling:,

Have you seen this old Cloud9 discussion on the topic? :

Solution below.
The $file argument seems to be confusing things. I get the same error you do. Then even when I specify the file (e.g. ./test/test.js) in the Command field, I get:

Mocha-testing /mnt/lincs/CouchLincs/mocha
debugger listening on port 5858
throw new Error("cannot resolve path (or pattern) '" + path + "'"); 

Since Mocha looks in ./test for *.js files to test, removing the file argument leads to “expected behavior” for me–when I select the runner and click run, mocha runs my tests (with debugging if I have debugging turned out). Here is the runner as I edited it, and then saved as “

"cmd": [
"info": "Mocha-testing $project_path",
"working_dir": "$project_path",
"env": {},
"debugger": "v8",
"debugport": 5858

and for complete referenceness, these discussions on Cloud9 + Mocha too:

:books: :snail: