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

node inspector #247

Closed
weepy opened this issue Feb 1, 2012 · 42 comments
Closed

node inspector #247

weepy opened this issue Feb 1, 2012 · 42 comments
Labels
type: feature enhancement proposal

Comments

@weepy
Copy link

weepy commented Feb 1, 2012

Hi

Is it possible for mocha to work with node inspector ?

I tried with mocha -d, but this seemed to just give the node debug prompt.

weepy

@tj
Copy link
Contributor

tj commented Feb 1, 2012

hmm i forget what the interface to node-inspector is, might have to try it out

@weepy
Copy link
Author

weepy commented Feb 1, 2012

you do either :

node --debug your/node/program.js

or

node --debug-brk your/node/program.js

On Wed, Feb 1, 2012 at 4:24 PM, TJ Holowaychuk
reply@reply.github.com
wrote:

hmm i forget what the interface to node-inspector is, might have to try it out


Reply to this email directly or view it on GitHub:
#247 (comment)

@balupton
Copy link

balupton commented Feb 3, 2012

This would be great. Tried debugging my tests with node-inspector and just couldn't seem to get it working. Could get mocha inside web inspector with node --debug ./node_modules/.bin/mocha but not the actual tests.

@tj
Copy link
Contributor

tj commented Feb 3, 2012

@weepy our --debug is node debug <script>, so I guess it's kinda ambiguous, what's the difference again? I've only really used node's build-in debugger

@balupton
Copy link

balupton commented Feb 3, 2012

Node inspector starts up a server which hooks into node's built-in debugger server, allowing you to debug node.js programs with webkit's developer tools (so say, inside google chrome).

... or at least that's how I think it works (could be wrong).

@tj
Copy link
Contributor

tj commented Feb 3, 2012

right right, so --debug just fires up v8's debugging protocol? hmMmmM wonder what to call it to get around the ambiguity issue

@tj
Copy link
Contributor

tj commented Feb 3, 2012

maybe mocha --debug should be changed to mocha debug to match node, that would probably be the best

@weepy
Copy link
Author

weepy commented Feb 3, 2012

agree

node-inspector is using --debug and --debug-brk

so it would be good to proxy those through.

On Fri, Feb 3, 2012 at 10:47 AM, TJ Holowaychuk
reply@reply.github.com
wrote:

maybe mocha --debug should be changed to mocha debug to match node, that would probably be the best


Reply to this email directly or view it on GitHub:
#247 (comment)

@zzen
Copy link

zzen commented Feb 3, 2012

Just ran over the same issue, needed to fire up node-inspector for a mocha test. --debug vs debug distinction would be cool

@tj
Copy link
Contributor

tj commented Feb 3, 2012

marked as high priority I'll make sure it gets in the next release

JamesMaroney added a commit to tnwinc/mocha that referenced this issue Feb 11, 2012
It is working well for me, following the path suggested by @visionmedia
Note: This does change the commandline operation of mocha by changing the --debug option's meaning
and instead, mapping the previous meaning to debug (no dashes)
@tj tj closed this as completed in 41e4118 Feb 15, 2012
@tj
Copy link
Contributor

tj commented Feb 15, 2012

that should fix it, I dont use node-inspector if anyone could confirm that would be great!

@zzen
Copy link

zzen commented Feb 16, 2012

  • mocha --debug-brk works as advertised

  • mocha --debug does the same as --debug-brk, which is wrong. As visible in this pair of ps lines:

    node /Users/jakub/.nvm/v0.4.12/bin/mocha --debug --reporter spec
    node --debug-brk /Users/jakub/.nvm/v0.4.12/lib/node_modules/mocha/bin/_mocha --debug --reporter spec
    

@tj
Copy link
Contributor

tj commented Feb 16, 2012

they work like node's --debug and --debug-brk for me

@zzen
Copy link

zzen commented Feb 16, 2012

If you look at the two lines from processlist above, you'll see that I've run mocha --debug which in turn ran node --debug-brk <path-to-_mocha> (instead of node --debug <path-to-_mocha>)

@tj
Copy link
Contributor

tj commented Feb 16, 2012

hmm odd that's not the case for me

@brendanjerwin
Copy link

This working for me.

Important: node-inspector doesn't play well with just plain old --debug, you need to use --debug-brk it seems to give things time to connect or something.

@weepy
Copy link
Author

weepy commented Feb 17, 2012

Not sure if related but I just saw a fix for debugbrk in node 6.11
On Feb 17, 2012 7:41 PM, "Brendan Erwin" <
reply@reply.github.com>
wrote:

This working for me.

Important: node-inspector doesn't play well with just plain old --debug,
you need to use --debug-brk it seems to give things time to connect or
something.


Reply to this email directly or view it on GitHub:
#247 (comment)

@zzen
Copy link

zzen commented Feb 17, 2012

OK, I'm not sure what's going on but I'm unable to replicate this on other versions of node or on other computers on the same version of node, so it seems to be my local configuration issue… On all other machines / versions it works as expected.

@ghost
Copy link

ghost commented Jun 2, 2012

i tried using mocha --debug-brk test.js and i could connect via node-inspector but my test script files did not show up in chromes debugger.

anyone else have this issue?

p.s. i'm on windows

@JudahGabriel
Copy link

I'm hitting the same issue as blackjable: I can connect via node-inspector, but no test script files show up in Chrome's debugger.

@chris-rock
Copy link

I think from technical perspective everything is fine within mocha. also node-inspector is working fine. anyhow the problem is, that node-inspector starts to debug the complete mocha source code. A simple solution would be, that mocha sets a auto-breakpoint at the first test case.

@duro
Copy link

duro commented Jan 2, 2013

I am having the same trouble, it's very difficult to get a breakpoint set inside a test. I've been trying to wade through the mocha source to try and get into a function that will let me set a breakpoint on my test, but I still haven't had any luck.

I've tried setting a "debugger;" in my source, but it still does not get caught in time.

+1 for Chris Rock's suggestion.

@JudahGabriel
Copy link

What I ended up having to do:

  1. Run node-inspector
  2. Run mocha --debug-brk
  3. Launch http://127.0.0.1:8080/debug?port=5858 in Chrome.
  4. Debugger is paused on the first line automatically. Go to the end of that file, set a breakpoint at the end.
  5. Hit F8 to continue to that last breakpoint.
  6. When the breakpoint is hit, all my test files are now loaded.

@pparavicini
Copy link

Thank you JudahGabriel for the nice summary and suggestion. I am not able to see my test files after following your suggestion. Nevertheless, I am able to see all the mocha files after following your instructions, and setting a breakpoint in mocha/lib/runnable.js in the first line of the method Runnable.prototype.run (line 154 in mocha 1.4.2). This seems to stop execution after all the test files are loaded, and before the tests are run.

I was able to deduce this by putting a breakpoint in node.js' util.inspect which shows in the file navigator when the debug session first starts, placing a console.log(util.inspect...) statement in my test, and consulting the CallStack.

I am using
Chromium-20.0.x on ubuntu-12.04,
node 0.8.16,
node-inspector-0.2.0beta3,
mocha-1.4.2

Thank you VisionMedia and Danny Coates for Mocha and node-inspector respectively

@deitch
Copy link

deitch commented Jul 28, 2013

Is there any update on this? Stepping through the mocha source line by line until all of my project source files are loaded is terribly painful.

I could always not run mocha command-line, instead require('mocha') in my own wrapper, but what a waste.

@bajtos
Copy link

bajtos commented Aug 1, 2013

We have released a new version of Node Inspector (0.3) which allows you to set breakpoints in files that are not loaded by node yet. This feature makes debugging of mocha unit-tests much easier:

  1. Run mocha unit-test in any project with –debug-brk option.
  2. Launch node-inspector.
  3. Look at source files of your unit-tests and set breakpoints inside them.
  4. Resume execution when you have all breakpoints set up
  5. Wait for debugger to hit your first breakpoint.

See our blog post for more details about the new Node Inspector version.

@deitch
Copy link

deitch commented Aug 1, 2013

I have the following trick I use. I create a file in my test/ folder called test-master.js. It has not describe(), just:

/*global debugger,v8debug,before,after */
/*jslint debug:true, node:true */

// call the debugger in case we are in debug mode
before(function (done) {
    if (typeof(v8debug) !== undefined) {
        debugger;
    }
    done();
});

Since all my other tests are in a describe(), this causes all of them to load, but the debugger statement to get instantiated if I am in debug mode only, after all files have loaded but before anything else runs.

With Chrome, works beautifully.

@gprasant
Copy link

Thanks @JudahGabriel . Your steps work

@manast
Copy link

manast commented Jun 1, 2014

@bajtos Im trying to follow your stepwise procedure for setting breakpoints on the mocha unit tests, but I get stucked in step 3, "Look at source files of your unit-tests and set breakpoints inside them.", what do you mean by "look" ? I mean, I can open a file explorer and look at the files, but no matter how much I concentrate on them they do not appear on the debugger :(

@JudahGabriel
Copy link

I bring up Chrome developer tools, CTRL+O to open a file, search for the
name of one of my unit tests, put a breakpoint inside that file.

On Sun, Jun 1, 2014 at 3:28 AM, Manuel Astudillo notifications@github.com
wrote:

@bajtos https://github.com/bajtos Im trying to follow your stepwise
procedure for setting breakpoints on the mocha unit tests, but I get
stucked in step 3, "Look at source files of your unit-tests and set
breakpoints inside them.", what do you mean by "look" ? I mean, I can open
a file explorer and look at the files, but no matter how much I concentrate
on them they do not appear on the debugger :(


Reply to this email directly or view it on GitHub
#247 (comment).

-Judah Gabriel Himango

@andrewroberts
Copy link

The node-inspector readme says run 'node-debug _mocha', which automatically stops on the first line.

@andrewroberts
Copy link

... and then I put "debugger" in the files under test (FUT). I couldn't find a way to open my FUTs from within chrome either. CTRL-O doesn't list any files only those under the mocha folder.

@bajtos
Copy link

bajtos commented Jul 20, 2014

@andrewroberts

  • what is the exact commandline you use to run the tests?
  • what is the platform?
  • how can I reproduce the problem on my machine?

@andrewroberts
Copy link

@bajtos thanks for getting back to me. I'm using node-debug _mocha to start node inspector (latest version to date as is node and mocha) in chrome (Version 35.0.1916.114). I guess I'd just like to know how to get to my test files without using debugger in the source, as CTRL-O doesn't seem to let me get to them.

@bajtos
Copy link

bajtos commented Jul 21, 2014

@andrewroberts Do you happen to run on Mac OSX? In which case the keyboard shortcut is Cmd+O.

Also when inside "Sources" tab, there is a small [|>] icon in the left-top part of the screen. When you click on it, a file navigator should open, listing all your source files in a tree-like view.

@andrewroberts
Copy link

I see the file navigator but it only shows the folder tree below the _mocha file that it's stopped on, and CTRL-O (Linux Mint 14 with WIndows keyboard) only shows the tree below this.

@stonebraker
Copy link

JudahGabriel, thank you! I've been trying here and there to figure out how to debug my app while tests are executing. Following the instructions provided in the node-inspector docs didn't do the trick. Your instructions however, worked perfectly. I can now step through my code while my tests are running making my workflow FAR more productive. Plus, it appears that I can go back to using mocha's --recursive option, allowing me to sanely organize tests. This is especially helpful since tests can't be placed throughout an app as far as I can tell.

@Zacknero
Copy link

Zacknero commented Oct 1, 2014

@bajtos Hello I'm developing a project with the block MEAN.JS and I have problems running the debug various file test.js that when I put the breakpoint generates errors that I can not "see" the module that loads the test.
Such as:
beforeeach (module (ApplicationConfiguration.applicationModuleName));
Where the debug stops on this line that can not "see" ApplicationConfiguration.applicationModuleName.

How can I solve this problem ?? :( Thanks!

@bajtos
Copy link

bajtos commented Oct 1, 2014

@Zacknero please provide a full code snippet, the example in your comment is not a valid mocha code. In general, you probably need to split your code into multiple lines, so that you can place the breakpoint inside the function body, as opposed to placing it on a line where the function is executed.

@Zacknero
Copy link

Zacknero commented Oct 1, 2014

(function() {
// Images Controller Spec
describe('Images Controller Tests', function() {
// Initialize global variables
var ImagesController,
scope,
number,
Images,
$httpBackend,
$stateParams,
$location;

    // The $resource service augments the response object with methods for updating and deleting the resource.
    // If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
    // the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
    // When the toEqualData matcher compares two objects, it takes only object properties into
    // account and ignores methods.
    beforeEach(function() {
        jasmine.addMatchers({
            toEqualData: function(util, customEqualityTesters) {
                return {
                    compare: function(actual, expected) {
                        return {
                            pass: angular.equals(actual, expected)
                        };
                    }
                };
            }
        });
    });

    // Then we can start by loading the main application module
    beforeEach(module(ApplicationConfiguration.applicationModuleName));

    // The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
    // This allows us to inject a service but then attach it to a variable
    // with the same name as the service.
    beforeEach(inject(function($controller, $rootScope, _$location_, _$stateParams_, _$httpBackend_,$filter,_Images_) {
        // Set a new global scope
        scope = $rootScope.$new();

        // Point global variables to injected services
        $stateParams = _$stateParams_;
        $httpBackend = _$httpBackend_;
        $location = _$location_;

        // Initialize the Images controller.
        //VARABLE FOR CONTROLLER
        ImagesController = $controller('ImagesController', {
            $scope: scope
        });

    /*-----START TEST CONTROLLER-----*/

    it(''Field input "imageSearch" empty', inject(function() {
        expect(scope.imageSearch).toBeUndefined();
    }));

.................. to more

and ApplicationConfiguration.applicationModuleName the variable is inside the file config.js

@bajtos
Copy link

bajtos commented Oct 1, 2014

The code is AngularJS code that you need to run in a browser, not via Node Inspector. If you are using Chrome Developer Tools to debug your test, then you can try to ask in Google Chrome Developer Tools. If you are using Karma Runner then you can try karma-users too.

@Zacknero
Copy link

Zacknero commented Oct 1, 2014

Thank you!! I'm going to get a better view of karma!

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

No branches or pull requests