Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell which tests take the most time in jasmine?

I noticed that the whole suite of Jasmine tests started taking more time that I would like, but I'm not sure, which ones actually cause the delay. Is there a way to find that out without running each test individually?

like image 690
Fluffy Avatar asked Dec 25 '12 11:12

Fluffy


1 Answers

The basic ConsoleReporter only reports the time elapsed for all the tests, but if you look at the source code of it you will see it's quite easy to modify to add the elapsed time for each spec. Basically what you need to do is to log the time a spec start when the function reportSpecStarting (that's just before a spec starts to run) is called and output the difference when the function reportSpecResults (that's just after a spec has finished running).

So if you modified the ConsoleReporter with this, it would output you the name of each specification with their elapsed time :

this.reportSpecStarting = function() {
    this.specStartingTime = this.now();
};

this.reportSpecResults = function(spec) {
    var results = spec.results();

    print(results.description + " ");

    if (results.skipped) {
        yellowStar();
    } else if (results.passed()) {
        greenDot();
    } else {
        redF();
    }

    print(" (" + (this.now() - this.specStartingTime) + "ms)");
    newline();
};
like image 56
HoLyVieR Avatar answered Nov 14 '22 23:11

HoLyVieR