2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
|
|
|
|
throw new Error("jasmine not loaded!");
|
|
|
|
}
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
jasmine.HeadlessConsoleReporter = (function() {
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
function HeadlessConsoleReporter(callback) {
|
|
|
|
this.callback = callback != null ? callback : null;
|
|
|
|
this.results = [];
|
|
|
|
this.failedCount = 0;
|
|
|
|
this.length = 0;
|
2011-11-21 16:33:51 +00:00
|
|
|
this.timer = null;
|
|
|
|
this.position = 0;
|
|
|
|
this.positions = "|/-\\";
|
2011-10-27 00:05:05 +00:00
|
|
|
}
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) {
|
|
|
|
var output, result, resultLine, runtime, _i, _len, _ref;
|
2011-11-22 15:36:42 +00:00
|
|
|
if (this.hasError()) return;
|
2011-10-27 00:05:05 +00:00
|
|
|
runtime = (new Date() - this.startTime) / 1000.0;
|
|
|
|
JHW.stdout.print("\n");
|
|
|
|
resultLine = this._formatResultLine(runtime);
|
|
|
|
if (this.failedCount === 0) {
|
|
|
|
JHW.stdout.puts(("PASS: " + resultLine).foreground('green'));
|
|
|
|
} else {
|
|
|
|
JHW.stdout.puts(("FAIL: " + resultLine).foreground('red'));
|
2011-11-05 18:19:41 +00:00
|
|
|
JHW.hasSpecFailure();
|
2011-10-27 00:05:05 +00:00
|
|
|
}
|
|
|
|
output = "TOTAL||" + this.length + "||" + this.failedCount + "||" + runtime + "||" + (JHW._hasErrors ? "T" : "F");
|
|
|
|
JHW.report.puts(output);
|
|
|
|
_ref = this.results;
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
|
result = _ref[_i];
|
|
|
|
result.print();
|
|
|
|
}
|
2011-11-22 15:36:42 +00:00
|
|
|
if (window.JHW) window.onbeforeunload = null;
|
2011-10-27 00:05:05 +00:00
|
|
|
return JHW.finishSuite();
|
|
|
|
};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) {
|
|
|
|
this.startTime = new Date();
|
2011-11-21 21:10:15 +00:00
|
|
|
if (!this.hasError()) {
|
|
|
|
return JHW.stdout.puts("\nRunning Jasmine specs...".bright());
|
|
|
|
}
|
2011-10-27 00:05:05 +00:00
|
|
|
};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) {
|
|
|
|
var failureResult, foundLine, result, results, testCount, _i, _len, _ref;
|
2011-11-22 15:36:42 +00:00
|
|
|
if (this.hasError()) return;
|
2011-11-10 18:52:42 +00:00
|
|
|
JHW.ping();
|
2011-10-27 00:05:05 +00:00
|
|
|
results = spec.results();
|
|
|
|
this.length++;
|
|
|
|
if (results.passed()) {
|
|
|
|
JHW.stdout.print('.'.foreground('green'));
|
|
|
|
return JHW.report.puts("PASS||" + spec.getJHWSpecInformation());
|
|
|
|
} else {
|
|
|
|
JHW.stdout.print('F'.foreground('red'));
|
|
|
|
JHW.report.puts("FAIL||" + spec.getJHWSpecInformation());
|
|
|
|
this.failedCount++;
|
|
|
|
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName());
|
|
|
|
testCount = 1;
|
|
|
|
_ref = results.getItems();
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
|
result = _ref[_i];
|
|
|
|
if (result.type === 'expect' && !result.passed_) {
|
|
|
|
if (foundLine = result.expectations[testCount - 1]) {
|
|
|
|
result.line = foundLine[0], result.lineNumber = foundLine[1];
|
|
|
|
}
|
|
|
|
failureResult.addResult(result);
|
|
|
|
}
|
|
|
|
testCount += 1;
|
|
|
|
}
|
|
|
|
return this.results.push(failureResult);
|
|
|
|
}
|
|
|
|
};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) {
|
|
|
|
if (this.hasError()) {
|
|
|
|
spec.finish();
|
|
|
|
return spec.suite.finish();
|
|
|
|
}
|
|
|
|
};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-11-21 16:33:51 +00:00
|
|
|
HeadlessConsoleReporter.prototype.reportSpecWaiting = function() {
|
|
|
|
var first, runner;
|
2011-11-22 15:36:42 +00:00
|
|
|
var _this = this;
|
2011-11-21 16:33:51 +00:00
|
|
|
runner = null;
|
|
|
|
if (!this.timer) {
|
|
|
|
this.timer = true;
|
|
|
|
first = true;
|
2011-11-22 15:36:42 +00:00
|
|
|
runner = function() {
|
|
|
|
return _this.timer = setTimeout(function() {
|
|
|
|
if (_this.timer) {
|
|
|
|
if (!first) JHW.stdout.print(Intense.moveBack());
|
|
|
|
JHW.stdout.print(_this.positions.substr(_this.position, 1).foreground('yellow'));
|
|
|
|
_this.position += 1;
|
|
|
|
_this.position %= _this.positions.length;
|
2011-11-21 16:33:51 +00:00
|
|
|
first = false;
|
|
|
|
return runner();
|
|
|
|
}
|
2011-11-22 15:36:42 +00:00
|
|
|
}, 750);
|
|
|
|
};
|
2011-11-21 16:33:51 +00:00
|
|
|
return runner();
|
|
|
|
}
|
|
|
|
};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-11-21 16:33:51 +00:00
|
|
|
HeadlessConsoleReporter.prototype.reportSpecRunning = function() {
|
|
|
|
if (this.timer) {
|
|
|
|
clearTimeout(this.timer);
|
|
|
|
this.timer = null;
|
|
|
|
return JHW.stdout.print(Intense.moveBack());
|
|
|
|
}
|
|
|
|
};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
HeadlessConsoleReporter.prototype.hasError = function() {
|
|
|
|
return JHW._hasErrors;
|
|
|
|
};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) {
|
|
|
|
var line;
|
|
|
|
line = [];
|
|
|
|
line.push(this.length);
|
|
|
|
line.push((this.length === 1 ? "test" : "tests") + ',');
|
|
|
|
line.push(this.failedCount);
|
|
|
|
line.push((this.failedCount === 1 ? "failure" : "failures") + ',');
|
|
|
|
line.push(runtime);
|
|
|
|
line.push((runtime === 1.0 ? "sec" : "secs") + '.');
|
|
|
|
return line.join(' ');
|
|
|
|
};
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
return HeadlessConsoleReporter;
|
2011-11-22 15:36:42 +00:00
|
|
|
|
2011-10-27 00:05:05 +00:00
|
|
|
})();
|