Debugging unit test that makes a http://localhost call back into my WebStorm project?

Hi:

I am running a unit test like so:


/*
Creates some submissions and tries to save them
*/
describe('canCreateAndSaveSubmissionModel',function() {
    it('tests that a model can be created and saved', function (done) {
        var numToCreate = 10;
        var helper = new HttpHelper();
        helper.getModel(function(status, model){
            var i = 0;
            var email = 'reselbob@gmail.com';
            var legacySite = 'xxx.com.trunk.test';
            var talxSite = 'xxx.com.trunk.test.talr ';
            model["reporter"] = email;
            model["legacy"]={"url":legacySite,"recordCount":random.integer(0,1000),"milliseconds":random.integer(0,500)};
            model["talr"]={"url":talxSite,"recordCount":random.integer(0,1000),"milliseconds":random.integer(0,500)};
            model["parameters"]={"height":62,"weight":150,"toes":10};
            model["hasImages"]=false;
            model["reportName"]="report-" + 0;
            helper.saveModel(model,function(status,data){
                assert.equal(200, status);
                assert.notEqual(data, undefined);
            });
            done();
        })


    })
});


Here is the helper....


var http = require('http');
var events = require('events');
var request = require('superagent');
module.exports = HttpHelper;



HttpHelper.prototype.saveModel = function(model, onComplete){
    var modelString = JSON.stringify(model);
    request
        .post('localhost:3000')
        .send(modelString)
        .set('Accept', 'application/json')
        .end(function(err, res){
            console.log('res here');
            if (res.ok) {
                console.log('yay got ' + JSON.stringify(res.body));
            } else {
                console.log('Oh no! error ' + res.text);
            }
        });
};


Both the unit test and the POST code are running under my WebStorm project. I am running the unit test using a Mocha configuration. I put a break point in the code behind the POST endpoint. But, when I run the unit test, I can step through the test code, but the code on the other side of the HTTP call does not load, nor is the breakpoint respected.

Tell me please, how to do I make it so I can debug both the test and the code behind the HTTP call?

Thanks in advance.

Bob

2 comments
Comment actions Permalink

Hey Bob,

Did you ever figure this out? I have the same issue. :-/

0
Comment actions Permalink

Yes.
1. Set your break points in both the unit test and the server code
2. go to bin/www, right click and starte in Debug mode
3. go to your unit test file, right click and start in Debug.


Hope this helps.

0

Please sign in to leave a comment.