Created
May 28, 2015 09:42
-
-
Save trodrigues/173239e316afb91ac81f to your computer and use it in GitHub Desktop.
timing reporter for jasmine
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
var timingReporter = { | |
suites: [{ | |
id: 'root', | |
description: 'Entire Suite', | |
children: [] | |
}], | |
getCurrentSuite: function () { | |
return _.last(this.suites); | |
}, | |
jasmineStarted: function(){ | |
this.getCurrentSuite().start = performance.now(); | |
}, | |
jasmineDone: function(){ | |
this.lastSuite.stop = performance.now(); | |
this.lastSuite.length = this.lastSuite.stop - this.lastSuite.start; | |
sortChildren(this.lastSuite); | |
printThing(this.lastSuite); | |
function printThing(thing) { | |
if (thing.children) { | |
console.groupCollapsed('%ims %o', thing.length, thing.description); | |
_.each(thing.children, printThing); | |
console.groupEnd(); | |
} else { | |
console.log('%ims %o', thing.length, thing.description); | |
} | |
} | |
function sortChildren(thing) { | |
if (thing.children) { | |
thing.children = _.sortBy(thing.children, function (child) { | |
return -child.length; | |
}); | |
_.each(thing.children, function (child) { | |
sortChildren(child); | |
}); | |
} | |
} | |
}, | |
suiteStarted: function(result){ | |
result.start = performance.now(); | |
result.children = []; | |
this.getCurrentSuite().children.push(result); | |
this.suites.push(result); | |
}, | |
suiteDone: function(result){ | |
result.stop = performance.now(); | |
result.length = result.stop - result.start; | |
this.lastSuite = this.suites.pop(); | |
}, | |
specStarted: function(result){ | |
var suite = this.getCurrentSuite(); | |
result.start = performance.now(); | |
suite.children.push(result); | |
}, | |
specDone: function(result){ | |
result.stop = performance.now(); | |
result.length = result.stop - result.start; | |
}, | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment