Open FredrikFolkesson opened 7 years ago
Spawning Mocha had to be done as the previous way just caused too many issues and the Mocha programmatic API is completely broken. This is indeed one of the downsides of spawning. To debug a single test file you could use the mocha
binary directly. I can't really think of a better solution right now, but happy to consider suggestions.
It is almost impossible to use code coverage since 4.0
Hi @FredrikFolkesson , the arguments are forwarded to the mocha process (https://github.com/sindresorhus/gulp-mocha/blob/master/index.js#L53), so you just have to pass --inspect-brk=xxxx
to mocha instead of to the node process (you basically add it at the end of the command)
If you're using VSCode, what it means is that you have to run your tests in a separate terminal, and while the tests are starting you can use the following configuration to attach to the process:
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"skipFiles": ["<node_internals>/**"]
},
I enabled debugging by adding 'inspect-brk': true
in my gulp task:
const mocha = require('gulp-mocha'),
// other code goes here
.pipe(mocha({
// other settings go here
'inspect-brk': true
}));
Since I'm using Rider, I followed these instructions to attach to the debug session:
Note that the approach above should work with WebStorm and other IntelliJ base IDEs.
Since gulp-mocha now spawns a new process running mocha we can no longer use the debugger to set breakpoints in our test code and then run the gulp task that runs our unit tests. (the process we attach to that runs gulp and gulp-mocha is not the one where the tests actually runs anymore since a new process is spawned to run mocha)
Is this something that will be fixed or will tests run by gulp-mocha not be debuggable anymore?