2011-05-12 21:02:11 +00:00
|
|
|
(function() {
|
2011-09-06 15:37:29 +00:00
|
|
|
var getSplitName, pauseAndRun;
|
2011-05-12 21:02:11 +00:00
|
|
|
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
|
|
|
}
|
2011-09-06 15:37:29 +00:00
|
|
|
getSplitName = function(parts) {
|
|
|
|
parts.push(String(this.description).replace(/[\n\r]/g, ' '));
|
|
|
|
return parts;
|
|
|
|
};
|
|
|
|
jasmine.Suite.prototype.getSuiteSplitName = function() {
|
|
|
|
return this.getSplitName(this.parentSuite ? this.parentSuite.getSuiteSplitName() : []);
|
|
|
|
};
|
|
|
|
jasmine.Spec.prototype.getSpecSplitName = function() {
|
|
|
|
return this.getSplitName(this.suite.getSuiteSplitName());
|
|
|
|
};
|
|
|
|
jasmine.Suite.prototype.getSplitName = getSplitName;
|
|
|
|
jasmine.Spec.prototype.getSplitName = getSplitName;
|
|
|
|
jasmine.Spec.prototype.getJHWSpecInformation = function() {
|
|
|
|
var parts, specLineInfo;
|
|
|
|
parts = this.getSpecSplitName();
|
|
|
|
specLineInfo = HeadlessReporterResult.findSpecLine(parts);
|
2011-09-06 20:48:19 +00:00
|
|
|
if (specLineInfo.file) {
|
|
|
|
parts.push("" + specLineInfo.file + ":" + specLineInfo.lineNumber);
|
|
|
|
} else {
|
|
|
|
parts.push('');
|
|
|
|
}
|
2011-09-06 15:37:29 +00:00
|
|
|
return parts.join("||");
|
|
|
|
};
|
2011-09-12 19:12:58 +00:00
|
|
|
jasmine.Spec.prototype.fail = function(e) {
|
|
|
|
var expectationResult, filename, realFilename;
|
2011-09-26 22:42:38 +00:00
|
|
|
if (e && e.sourceURL && window.CoffeeScriptToFilename) {
|
2011-09-12 19:12:58 +00:00
|
|
|
filename = e.sourceURL.split('/').pop();
|
|
|
|
if (realFilename = window.CoffeeScriptToFilename[filename]) {
|
|
|
|
e = {
|
|
|
|
name: e.name,
|
|
|
|
message: e.message,
|
|
|
|
lineNumber: "~" + String(e.line),
|
|
|
|
sourceURL: realFilename
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expectationResult = new jasmine.ExpectationResult({
|
|
|
|
passed: false,
|
|
|
|
message: e ? jasmine.util.formatException(e) : 'Exception',
|
|
|
|
trace: {
|
|
|
|
stack: e.stack
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return this.results_.addResult(expectationResult);
|
|
|
|
};
|
2011-09-12 19:38:40 +00:00
|
|
|
jasmine.NestedResults.isValidSpecLine = function(line) {
|
|
|
|
return line.match(/^\s*expect/) !== null || line.match(/^\s*return\s*expect/) !== null;
|
|
|
|
};
|
|
|
|
jasmine.NestedResults.parseFunction = function(func) {
|
|
|
|
var line, lineCount, lines, _i, _len, _ref;
|
|
|
|
lines = [];
|
|
|
|
lineCount = 0;
|
|
|
|
_ref = func.split("\n");
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
|
line = _ref[_i];
|
|
|
|
if (jasmine.NestedResults.isValidSpecLine(line)) {
|
|
|
|
line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, '');
|
|
|
|
lines.push([line, lineCount]);
|
|
|
|
}
|
|
|
|
lineCount += 1;
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
};
|
|
|
|
jasmine.NestedResults.parseAndStore = function(func) {
|
|
|
|
if (!jasmine.NestedResults.ParsedFunctions[func]) {
|
|
|
|
jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func);
|
|
|
|
}
|
|
|
|
return jasmine.NestedResults.ParsedFunctions[func];
|
|
|
|
};
|
|
|
|
jasmine.NestedResults.ParsedFunctions = [];
|
2011-09-06 15:37:29 +00:00
|
|
|
if (!jasmine.WaitsBlock.prototype._execute) {
|
|
|
|
jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute;
|
|
|
|
jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute;
|
|
|
|
pauseAndRun = function(onComplete) {
|
|
|
|
JHW.timerPause();
|
|
|
|
return this._execute(function() {
|
|
|
|
JHW.timerDone();
|
|
|
|
return onComplete();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
jasmine.WaitsBlock.prototype.execute = pauseAndRun;
|
|
|
|
jasmine.WaitsForBlock.prototype.execute = pauseAndRun;
|
2011-09-12 19:12:58 +00:00
|
|
|
jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult;
|
|
|
|
jasmine.NestedResults.prototype.addResult = function(result) {
|
|
|
|
result.expectations = [];
|
2011-09-12 19:38:40 +00:00
|
|
|
result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString());
|
2011-09-12 19:12:58 +00:00
|
|
|
return this.addResult_(result);
|
|
|
|
};
|
2011-09-06 15:37:29 +00:00
|
|
|
}
|
2011-07-14 14:54:44 +00:00
|
|
|
window.HeadlessReporterResult = (function() {
|
2011-07-13 18:42:47 +00:00
|
|
|
function HeadlessReporterResult(name, splitName) {
|
2011-05-12 21:02:11 +00:00
|
|
|
this.name = name;
|
2011-07-13 18:42:47 +00:00
|
|
|
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() {
|
2011-07-13 18:42:47 +00:00
|
|
|
var bestChoice, output, result, _i, _len, _ref, _results;
|
|
|
|
output = this.name;
|
2011-09-02 19:52:19 +00:00
|
|
|
bestChoice = HeadlessReporterResult.findSpecLine(this.splitName);
|
2011-07-13 18:42:47 +00:00
|
|
|
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];
|
2011-09-12 19:12:58 +00:00
|
|
|
output = result.message;
|
|
|
|
if (result.lineNumber) {
|
2011-09-12 19:38:40 +00:00
|
|
|
output += " (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")\n " + result.line;
|
2011-09-12 19:12:58 +00:00
|
|
|
}
|
|
|
|
_results.push(JHW.printResult(output));
|
2011-05-12 21:02:11 +00:00
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
};
|
2011-09-02 19:52:19 +00:00
|
|
|
HeadlessReporterResult.findSpecLine = function(splitName) {
|
2011-07-14 14:54:44 +00:00
|
|
|
var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref;
|
2011-07-13 18:42:47 +00:00
|
|
|
bestChoice = {
|
|
|
|
accuracy: 0,
|
|
|
|
file: null,
|
|
|
|
lineNumber: null
|
|
|
|
};
|
2011-07-14 14:54:44 +00:00
|
|
|
_ref = HeadlessReporterResult.specLineNumbers;
|
|
|
|
for (file in _ref) {
|
|
|
|
lines = _ref[file];
|
2011-07-13 18:42:47 +00:00
|
|
|
index = 0;
|
2011-07-14 14:54:44 +00:00
|
|
|
lineNumber = 0;
|
2011-09-02 19:52:19 +00:00
|
|
|
while (newLineNumberInfo = lines[splitName[index]]) {
|
2011-07-14 14:54:44 +00:00
|
|
|
if (newLineNumberInfo.length === 0) {
|
|
|
|
lineNumber = newLineNumberInfo[0];
|
|
|
|
} else {
|
|
|
|
lastLine = null;
|
|
|
|
for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) {
|
|
|
|
line = newLineNumberInfo[_i];
|
|
|
|
lastLine = line;
|
|
|
|
if (line > lineNumber) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lineNumber = lastLine;
|
|
|
|
}
|
2011-07-13 18:42:47 +00:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
if (index > bestChoice.accuracy) {
|
|
|
|
bestChoice = {
|
|
|
|
accuracy: index,
|
|
|
|
file: file,
|
|
|
|
lineNumber: lineNumber
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bestChoice;
|
|
|
|
};
|
2011-05-12 21:02:11 +00:00
|
|
|
return HeadlessReporterResult;
|
|
|
|
})();
|
|
|
|
jasmine.HeadlessReporter = (function() {
|
2011-07-22 11:42:25 +00:00
|
|
|
function HeadlessReporter(callback) {
|
|
|
|
this.callback = callback != null ? callback : null;
|
2011-05-12 21:02:11 +00:00
|
|
|
this.results = [];
|
|
|
|
this.failedCount = 0;
|
|
|
|
this.length = 0;
|
|
|
|
}
|
|
|
|
HeadlessReporter.prototype.reportRunnerResults = function(runner) {
|
2011-07-22 13:40:40 +00:00
|
|
|
var result, _i, _len, _ref;
|
2011-08-07 18:45:57 +00:00
|
|
|
if (this.hasError()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-05-12 21:02:11 +00:00
|
|
|
_ref = this.results;
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
|
result = _ref[_i];
|
2011-07-22 13:40:40 +00:00
|
|
|
result.print();
|
2011-05-12 21:02:11 +00:00
|
|
|
}
|
2011-07-22 11:42:25 +00:00
|
|
|
if (this.callback) {
|
|
|
|
this.callback();
|
|
|
|
}
|
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-09-12 19:12:58 +00:00
|
|
|
var failureResult, foundLine, result, results, testCount, _i, _len, _ref;
|
2011-08-07 18:45:57 +00:00
|
|
|
if (this.hasError()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-05-16 02:42:02 +00:00
|
|
|
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-09-02 19:52:19 +00:00
|
|
|
return JHW.specPassed(spec.getJHWSpecInformation());
|
2011-05-12 21:02:11 +00:00
|
|
|
} else {
|
2011-09-02 19:52:19 +00:00
|
|
|
JHW.specFailed(spec.getJHWSpecInformation());
|
2011-06-08 17:47:51 +00:00
|
|
|
this.failedCount++;
|
2011-07-13 18:42:47 +00:00
|
|
|
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName());
|
2011-09-12 19:12:58 +00:00
|
|
|
testCount = 1;
|
2011-05-16 02:42:02 +00:00
|
|
|
_ref = results.getItems();
|
2011-05-12 21:02:11 +00:00
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
|
result = _ref[_i];
|
2011-07-22 13:40:40 +00:00
|
|
|
if (result.type === 'expect' && !result.passed_) {
|
2011-09-12 19:12:58 +00:00
|
|
|
if (foundLine = result.expectations[testCount - 1]) {
|
2011-09-12 19:38:40 +00:00
|
|
|
result.line = foundLine[0], result.lineNumber = foundLine[1];
|
2011-09-12 19:12:58 +00:00
|
|
|
}
|
|
|
|
failureResult.addResult(result);
|
2011-07-22 13:40:40 +00:00
|
|
|
}
|
2011-09-12 19:12:58 +00:00
|
|
|
testCount += 1;
|
2011-05-12 21:02:11 +00:00
|
|
|
}
|
|
|
|
return this.results.push(failureResult);
|
|
|
|
}
|
|
|
|
};
|
2011-08-07 18:45:57 +00:00
|
|
|
HeadlessReporter.prototype.reportSpecStarting = function(spec) {
|
|
|
|
if (this.hasError()) {
|
|
|
|
spec.finish();
|
|
|
|
return spec.suite.finish();
|
|
|
|
}
|
|
|
|
};
|
2011-06-08 17:46:08 +00:00
|
|
|
HeadlessReporter.prototype.reportSuiteResults = function(suite) {};
|
2011-08-07 18:45:57 +00:00
|
|
|
HeadlessReporter.prototype.hasError = function() {
|
|
|
|
return JHW.hasError();
|
|
|
|
};
|
2011-05-12 21:02:11 +00:00
|
|
|
return HeadlessReporter;
|
|
|
|
})();
|
|
|
|
}).call(this);
|