jasmine-headless-webkit/vendor/assets/javascripts/jasmine.HeadlessReporter.Console.js

116 lines
4.1 KiB
JavaScript
Raw Normal View History

2011-12-12 17:22:32 +00:00
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
jasmine.HeadlessReporter.Console = (function() {
__extends(Console, jasmine.HeadlessReporter);
2011-12-12 17:22:32 +00:00
function Console(callback) {
2011-10-27 00:05:05 +00:00
this.callback = callback != null ? callback : null;
2011-12-12 17:22:32 +00:00
this._waitRunner = __bind(this._waitRunner, this);
Console.__super__.constructor.call(this, this.callback);
this.position = 0;
this.positions = "|/-\\";
2011-10-27 00:05:05 +00:00
}
Console.prototype.reportRunnerResults = function(runner) {
2011-12-12 17:22:32 +00:00
var result, resultLine, _i, _len, _ref;
Console.__super__.reportRunnerResults.call(this);
2011-12-29 23:37:23 +00:00
this.print("\n");
2011-12-12 17:22:32 +00:00
resultLine = this.formatResultLine(this._runtime());
2011-10-27 00:05:05 +00:00
if (this.failedCount === 0) {
2011-12-29 23:37:23 +00:00
this.puts(("PASS: " + resultLine).foreground('green'));
2011-10-27 00:05:05 +00:00
} else {
2011-12-29 23:37:23 +00:00
this.puts(("FAIL: " + resultLine).foreground('red'));
2011-10-27 00:05:05 +00:00
}
_ref = this.results;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
2011-12-29 23:37:23 +00:00
this.puts(result.toString());
2011-10-27 00:05:05 +00:00
}
2011-12-29 23:37:23 +00:00
return this.puts("\nTest ordering seed: --seed " + (JHW.getSeed()));
2011-10-27 00:05:05 +00:00
};
Console.prototype.reportRunnerStarting = function(runner) {
Console.__super__.reportRunnerStarting.call(this, runner);
if (!this.hasError()) {
2011-12-29 23:37:23 +00:00
return this.puts("\nRunning Jasmine specs...".bright());
}
2011-10-27 00:05:05 +00:00
};
Console.prototype.reportSpecResults = function(spec) {
2011-12-12 17:22:32 +00:00
var _this = this;
Console.__super__.reportSpecResults.call(this, spec);
2011-12-12 17:22:32 +00:00
return this._reportSpecResult(spec, {
success: function(results) {
2011-12-29 23:37:23 +00:00
return _this.print('.'.foreground('green'));
2011-12-12 17:22:32 +00:00
},
failure: function(results) {
var failureResult, foundLine, result, testCount, _i, _len, _ref;
2011-12-29 23:37:23 +00:00
_this.print('F'.foreground('red'));
2011-12-12 17:22:32 +00:00
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);
2011-10-27 00:05:05 +00:00
}
2011-12-12 17:22:32 +00:00
testCount += 1;
2011-10-27 00:05:05 +00:00
}
2011-12-12 17:22:32 +00:00
return _this.results.push(failureResult);
2011-10-27 00:05:05 +00:00
}
2011-12-12 17:22:32 +00:00
});
2011-10-27 00:05:05 +00:00
};
Console.prototype.reportSpecWaiting = function() {
if (!this.timer) {
this.timer = true;
2011-12-12 17:22:32 +00:00
this.first = true;
return this._waitRunner();
}
};
Console.prototype.reportSpecRunning = function() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
2011-12-29 23:37:23 +00:00
return this.print(Intense.moveBack());
}
};
Console.prototype.formatResultLine = function(runtime) {
2011-10-27 00:05:05 +00:00
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(' ');
};
Console.prototype._waitRunner = function() {
2011-12-12 17:22:32 +00:00
var _this = this;
return this.timer = setTimeout(function() {
if (_this.timer) {
2011-12-29 23:37:23 +00:00
if (!_this.first) _this.print(Intense.moveBack());
_this.print(_this.positions.substr(_this.position, 1).foreground('yellow'));
2011-12-12 17:22:32 +00:00
_this.position += 1;
_this.position %= _this.positions.length;
_this.first = false;
return _this._waitRunner();
}
}, 750);
};
return Console;
2011-10-27 00:05:05 +00:00
})();
2011-12-12 17:22:32 +00:00
}).call(this);