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

Problem

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?

Problem courtesy of: Fluffy

Solution

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();
};
Solution courtesy of: HoLyVieR

Discussion

what about using Jasmines HTMLReporter? (down towards the bottom) http://pivotal.github.com/jasmine/

hmmm.. maybe you can loop it so each file is executed individually? (not the best answer :( ) http://elegantcode.com/2011/03/07/taking-baby-steps-with-node-js-bdd-style-unit-tests-with-jasmine-node-sprinkled-with-some-should/

Discussion courtesy of: thescientist

This recipe can be found in it's original form on Stack Over Flow.