jasmine-headless-webkit/jasmine/jasmine.headless-reporter.js

121 lines
4.0 KiB
JavaScript
Raw Normal View History

2011-05-12 21:02:11 +00:00
(function() {
var HeadlessReporterResult;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
2011-06-13 12:14:24 +00:00
throw new Error("jasmine not laoded!");
2011-05-12 21:02:11 +00:00
}
HeadlessReporterResult = (function() {
function HeadlessReporterResult(name, splitName) {
2011-05-12 21:02:11 +00:00
this.name = name;
this.splitName = splitName;
2011-05-12 21:02:11 +00:00
this.results = [];
}
2011-05-12 22:47:56 +00:00
HeadlessReporterResult.prototype.addResult = function(message) {
return this.results.push(message);
};
2011-05-12 21:02:11 +00:00
HeadlessReporterResult.prototype.print = function() {
var bestChoice, output, result, _i, _len, _ref, _results;
output = this.name;
bestChoice = this._findSpecLine();
if (bestChoice.file) {
output += " (" + bestChoice.file + ":" + bestChoice.lineNumber + ")";
}
JHW.printName(output);
2011-05-12 21:02:11 +00:00
_ref = this.results;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
_results.push(__bind(function(result) {
return JHW.printResult(result);
}, this)(result));
}
return _results;
};
HeadlessReporterResult.prototype._findSpecLine = function() {
var bestChoice, file, index, lineNumber, lines, newLineNumber;
bestChoice = {
accuracy: 0,
file: null,
lineNumber: null
};
for (file in SPEC_LINE_NUMBERS) {
lines = SPEC_LINE_NUMBERS[file];
index = 0;
while (newLineNumber = lines[this.splitName[index]]) {
index++;
lineNumber = newLineNumber;
}
if (index > bestChoice.accuracy) {
bestChoice = {
accuracy: index,
file: file,
lineNumber: lineNumber
};
}
}
return bestChoice;
};
2011-05-12 21:02:11 +00:00
return HeadlessReporterResult;
})();
jasmine.Suite.prototype.getSuiteSplitName = function() {
var parts;
parts = this.parentSuite ? this.parentSuite.getSuiteSplitName() : [];
parts.push(this.description);
return parts;
};
jasmine.Spec.prototype.getSpecSplitName = function() {
var parts;
parts = this.suite.getSuiteSplitName();
parts.push(this.description);
return parts;
};
2011-05-12 21:02:11 +00:00
jasmine.HeadlessReporter = (function() {
function HeadlessReporter() {
this.results = [];
this.failedCount = 0;
this.length = 0;
}
HeadlessReporter.prototype.reportRunnerResults = function(runner) {
var result, _fn, _i, _len, _ref;
_ref = this.results;
_fn = __bind(function(result) {
return result.print();
}, this);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
_fn(result);
}
2011-05-12 22:47:56 +00:00
return JHW.finishSuite((new Date() - this.startTime) / 1000.0, this.length, this.failedCount);
};
HeadlessReporter.prototype.reportRunnerStarting = function(runner) {
return this.startTime = new Date();
2011-05-12 21:02:11 +00:00
};
HeadlessReporter.prototype.reportSpecResults = function(spec) {
2011-05-16 02:42:02 +00:00
var failureResult, result, results, _fn, _i, _len, _ref;
results = spec.results();
2011-06-08 17:47:51 +00:00
this.length++;
2011-05-16 02:42:02 +00:00
if (results.passed()) {
2011-05-12 21:02:11 +00:00
return JHW.specPassed();
} else {
JHW.specFailed(spec.getSpecSplitName().join('||'));
2011-06-08 17:47:51 +00:00
this.failedCount++;
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName());
2011-05-16 02:42:02 +00:00
_ref = results.getItems();
2011-05-12 21:02:11 +00:00
_fn = __bind(function(result) {
if (result.type === 'expect' && !result.passed_) {
2011-05-12 22:47:56 +00:00
return failureResult.addResult(result.message);
2011-05-12 21:02:11 +00:00
}
}, this);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
_fn(result);
}
return this.results.push(failureResult);
}
};
2011-05-12 22:47:56 +00:00
HeadlessReporter.prototype.reportSpecStarting = function(spec) {};
HeadlessReporter.prototype.reportSuiteResults = function(suite) {};
2011-05-12 21:02:11 +00:00
return HeadlessReporter;
})();
}).call(this);