3

When I run mocha with --debug-brk and open chrome dev tools with node-inspector, the debugger skips over any debugger statements that I put in my specfile.

I can get debugger statements to work in module files provided I follow this trick of placing a breakpoint at the bottom of the mocha lib.

Has anybody else seen this problem?

2
  • What version of node-inspector are you using? Jun 26, 2013 at 18:35
  • @MiroslavBajtoš 0.2.0beta4
    – Thomas
    Jun 26, 2013 at 18:40

2 Answers 2

2

It seems that everybody should be seeing the same problem with node-inspector version 0.2.0beta4.

The problem is in the way how breakpoints are managed:

  • The front-end remembers break-points in browser's local storage and restores them after the relevant file is loaded.
  • When you start mocha with --debug-brk and stop on the first line, your specfiles are not loaded yet, so the front-end does not restore your breakpoints.
  • When you resume mocha execution, front-end can't restore breakpoints quickly enough in the short window between a specfile is parsed and run. In fact mocha may exit before the V8 debugger has a change to notify front-end about new scripts being parsed!

Another workaround for this issue is to add debugger; statement in the specfile where you want to trigger a breakpoint.

EDIT

Note that the solution mentioned in node-inspector issue on github will work if you set breakpoint inside your it callback (i.e. spec implementation) but it won't help you with setting a breakpoint in the code which builds spec description (i.e. top-level code in your specfile and all describe callbacks).

Example:

var expect = require('chai').expect;
var calculator = require('./StringCalculator');

// CANNOT break on the line below
describe('add', function() {
  // CANNOT break on the line below
  it('returns 0 for empty string', function() {
    // CAN break on the line below
    expect(calculator.add('')).to.equal(0);
  });
});

EDIT2

The problem is fixed in my fork of node-inspector: https://github.com/strongloop/node-inspector. You can set breakpoints anywhere in your specfiles immediately after the node-inspector UI is loaded in your browser.

0

See my answer to a related question here: https://stackoverflow.com/a/29351654/3304034 for a decent enough work around

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.