Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer possible to debug mocha tests #170

Open
FredrikFolkesson opened this issue Apr 4, 2017 · 4 comments
Open

No longer possible to debug mocha tests #170

FredrikFolkesson opened this issue Apr 4, 2017 · 4 comments

Comments

@FredrikFolkesson
Copy link

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?

@sindresorhus
Copy link
Owner

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.

@zoltan-mihalyi
Copy link

It is almost impossible to use code coverage since 4.0

@micaste
Copy link

micaste commented Mar 13, 2020

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>/**"]
    },

@nzbart
Copy link

nzbart commented May 4, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants