Created
July 18, 2015 18:14
-
-
Save lencioni/7dcb8b9e47a059e89b32 to your computer and use it in GitHub Desktop.
Jasmine slow spec reporter
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
// 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