Debugging jasmine-node tests with node-inspector

前端 未结 3 1390
时光说笑
时光说笑 2020-12-13 06:55

Does anyone have any idea if this is possible? Most of the sample for node-inspector seemed geared toward debugging an invoked webpage. I\'d like to be able to debug jasmine

相关标签:
3条回答
  • 2020-12-13 06:57

    I ended up writing a little util called toggle:

    require('tty').setRawMode(true);
    var stdin = process.openStdin();
    
    exports.toggle = function(fireThis)
    {
        if (process.argv.indexOf("debug")!=-1)
        {
            console.log("debug flag found, press any key to start or rerun. Press 'ctrl-c' to cancel out!");
            stdin.on('keypress', function (chunk, key) {
                if (key.name == 'c' && key.ctrl == true)
                {
                    process.exit();
                }
                fireThis();
            });
        }
        else
        {
            console.log("Running, press any key to rerun or ctrl-c to exit.");
            fireThis();
            stdin.on('keypress', function (chunk, key) {
                if (key.name == 'c' && key.ctrl == true)
                {
                    process.exit();
                }
                fireThis();
            });
    
    
    
        }
    }
    

    You can drop it into your unit tests like:

    var toggle = require('./toggle');
    
    toggle.toggle(function(){
    
        var vows = require('vows'),
        assert = require('assert');
    
        vows.describe('Redis Mass Data Storage').addBatch({
    
    ....
    

    And then run your tests like: node --debug myfile.js debug. If you run debug toggle will wait until you anything but ctrl-c. Ctrl-c exits. You can also rerun, which is nice.

    w0000t.

    0 讨论(0)
  • 2020-12-13 07:00

    My uneducated guess is that you'd need to patch jasmine, I believe it spawns a new node process or something when running tests, and these new processes would need to be debug-enabled.

    I had a similar desire and managed to get expressso working using Eclipse as a debugger: http://groups.google.com/group/nodejs/browse_thread/thread/af35b025eb801f43

    …but I realised: if I needed to step through my code to understand it, I probably need to refactor the code (probably to be more testable), or break my tests up into smaller units.

    Your tests is your debugger.

    0 讨论(0)
  • 2020-12-13 07:09

    In short, just debug jasmine-node:

    node --debug-brk node_modules/jasmine-node/lib/jasmine-node/cli.js spec/my_spec.js
    

    If you look at the source of the jasmine-node script, it just invokes cli.js, and I found I could debug that script just fine.

    I wanted to use node-inspector to debug a CoffeeScript test. Just adding the --coffee switch worked nicely, e.g.

    node --debug-brk node_modules/jasmine-node/lib/jasmine-node/cli.js --coffee spec/my_spec.coffee
    
    0 讨论(0)
提交回复
热议问题