Skip to content

Instantly share code, notes, and snippets.

@lencioni
Created July 18, 2015 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lencioni/7dcb8b9e47a059e89b32 to your computer and use it in GitHub Desktop.
Save lencioni/7dcb8b9e47a059e89b32 to your computer and use it in GitHub Desktop.
Jasmine slow spec reporter
// A custom Jasmine reporter that logs slow specs.
const warnThresholdMs = 300;
const slowSpecsToPrint = 10;
function now() {
return (new Date()).getTime();
}
const slowReporter = {
jasmineStarted() {
this._specTimes = [];
},
specStarted() {
this._specStartedTime = now();
},
specDone(result) {
const time = now() - this._specStartedTime;
this._specTimes.push({ fullName: result.fullName, time: time });
if (time >= warnThresholdMs) {
console.warn(`${result.fullName} took ${time}ms`);
}
},
jasmineDone() {
// Print out top slow specs in order
const slowestSpecs = this._specTimes.sort((a, b) => b.time - a.time)
.slice(0, slowSpecsToPrint);
console.log(`${slowSpecsToPrint} slowest specs:`);
console.table(slowestSpecs);
},
};
jasmine.getEnv().addReporter(slowReporter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment