Skip to content

Instantly share code, notes, and snippets.

@trodrigues
Created May 28, 2015 09:42
Show Gist options
  • Save trodrigues/173239e316afb91ac81f to your computer and use it in GitHub Desktop.
Save trodrigues/173239e316afb91ac81f to your computer and use it in GitHub Desktop.
timing reporter for jasmine
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