Skip to content

Instantly share code, notes, and snippets.

@akahigeg
Created Dec 10, 2010
Embed
What would you like to do?
TitaniumReporter for Jasmine
(function() {
if (! jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
var TitaniumReporter = function() {};
TitaniumReporter.prototype = {
reportRunnerStarting: function(runner) {
this.startedAt = new Date();
this.info("Runner Started.");
},
reportRunnerResults: function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
specCount++;
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
results.failedCount > 0 ? this.error(message) : this.info(message);
this.info("Runner Finished.");
},
reportSpecStarting: function(spec) {
this.debug(spec.suite.description + ' : ' + spec.description + ' ... ');
},
reportSpecResults: function(spec) {
var resultText = "Failed.";
var results = spec.results();
if (spec.results().passed()) {
return this.debug("Passed.");
}
var resultItems = results.getItems();
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
this.info(result.toString());
} else if (result.type == 'expect' && result.passed && !result.passed()) {
this.error(spec.suite.description + ' : ' + spec.description + ' ... ');
this.error(result.message);
}
}
},
reportSuiteResults: function(suite) {
var results = suite.results();
var message = suite.description + ": " + results.passedCount + " of " + results.totalCount + " passed.";
if (results.passedCount == results.totalCount) {
this.debug(message);
} else {
this.error(message);
}
},
log: function(str, logLevel) {
switch (logLevel) {
case "warn":
Ti.API.warn(str);
break;
case "debug":
Ti.API.debug(str);
break;
case "error":
Ti.API.error(str);
break;
case "info":
default:
Ti.API.info(str);
break;
}
},
error: function(str) { this.log(str, "error"); },
warn: function(str) { this.log(str, "warn"); },
info: function(str) { this.log(str, "info"); },
debug: function(str) { this.log(str, "debug"); }
};
// export public
jasmine.TitaniumReporter = TitaniumReporter;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment