Reputation: 45
Does anyone know how to configure VSCode to debug Mocha tests when executing via a test script? Setup is:
I want to be able to debug the execution of these individual tests(i.e. run 'npm test -- -g "test description"' in VSCode and break in VSCode's Debug view when it reaches a bp). Is this possible? Would an 'attach' config be needed instead of 'launch'?
I've tried the standard debug configs provided in VSCode , and tried to modify them based on info found in various places, but no success so far. Any help would be great, not too familiar with the IDE, or any of these processes Thanks!
Upvotes: 0
Views: 2925
Reputation: 35
Late answer but it may help people falling on this question.
Adding inspect-brk will hold the process until you connect your debugger, vscode in this case. After that tests will run and stop on your debug points. Usually the listening port for debugging is 9229, but you'll see the correct port on the sysout.
mocha --inspect-brk test.js
Credits to Run node inspector with mocha
Upvotes: 1
Reputation: 61
You can attach vs code debugger to a process launched by script
For that you need to:
1) Add mocha
's --inspect
option to your script
2) Configure your launch.json this way
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Mocha: tests",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector",
},
]
3) After running your script hit F5
and pick mocha's process from vs code popped up processes list (you need to be quick here :) )
4) Second time you run the script and hit F5
vs code will automatically pick the right process for you
Upvotes: 0