Skip to content

Instantly share code, notes, and snippets.

@lightsofapollo
Created January 8, 2012 05:59
Show Gist options
  • Save lightsofapollo/1577413 to your computer and use it in GitHub Desktop.
Save lightsofapollo/1577413 to your computer and use it in GitHub Desktop.
Jasmine reporter to find slow running tests
SlowDescribeReporter.prototype = {
threshold: 400,
reportRunnerStarting: function(runner){
var i, len, suites = runner.suites_, self = this;
this.topLevels = {};
for(i = 0, len = suites.length; i < len; i++){
(function(exec){
suites[i].execute = function(){
self.topLevels[this.id].start = new Date();
exec.apply(this, arguments);
};
}(suites[i].execute));
this.topLevels[suites[i].id] = {
start: null,
stop: null
}
}
},
reportRunnerResults: function(runner){
},
resultsForSpecs: function(){
},
reportSuiteResults: function(suite){
var start, stop, ms;
if(this.topLevels[suite.id]){
start = this.topLevels[suite.id].start;
stop = this.topLevels[suite.id].stop = new Date();
if(!start || !stop){
console.log(suite.description, 'failed', start, stop);
} else {
ms = (stop.getTime() - start.getTime());
if(ms > this.threshold){
console.log(suite.getFullName(), 'completed in ', ms / 1000, 'seconds (', ms, ' ms)');
}
}
}
},
reportSpecStarting: function(spec){
},
reportSpecResults: function(spec){
}
};
@jipiboily
Copy link

I wrote something simple to find the slowest running specs in Jasmine 2.3, might be useful to others: http://jipiboily.com/how-to-know-jasmine-specs-are-slow/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment