Created
January 8, 2012 05:59
-
-
Save lightsofapollo/1577413 to your computer and use it in GitHub Desktop.
Jasmine reporter to find slow running tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ | |
} | |
}; |
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
You can use this to add it to your env (like a spec helper)