Merge branch 'sprockets-integration' of github.com:johnbintz/jasmine-headless-webkit into sprockets-integration

This commit is contained in:
John Bintz 2011-11-21 20:19:05 -05:00
commit 130a65ecdd
8 changed files with 51 additions and 62 deletions

View File

@ -23,7 +23,15 @@
if (window.JHW) { if (window.JHW) {
jasmine.getEnv().addReporter(new jasmine.HeadlessConsoleReporter()); jasmine.getEnv().addReporter(new jasmine.HeadlessConsoleReporter());
} else { } else {
jasmine.getEnv().addReporter(new jasmine.HtmlReporter()); types = [ 'HtmlReporter', 'TrivialReporter' ];
for (var i = 0, j = types.length; i < j; ++i) {
var type = jasmine[types[i]]
if (type) {
jasmine.getEnv().addReporter(new type());
break;
}
}
} }
jasmine.getEnv().execute(); jasmine.getEnv().execute();

View File

@ -11,7 +11,7 @@ class window.HeadlessReporterResult
bestChoice = HeadlessReporterResult.findSpecLine(@splitName) bestChoice = HeadlessReporterResult.findSpecLine(@splitName)
output += " (#{bestChoice.file}:#{bestChoice.lineNumber})".foreground('blue') if bestChoice.file output += " (#{bestChoice.file}:#{bestChoice.lineNumber})".foreground('blue') if bestChoice.file
JHW.stdout.puts "\n\n#{output}" JHW.stdout.puts "\n#{output}"
for result in @results for result in @results
output = result.message.foreground('red') output = result.message.foreground('red')
if result.lineNumber if result.lineNumber

View File

@ -37,7 +37,7 @@ class jasmine.HeadlessConsoleReporter
reportRunnerStarting: (runner) -> reportRunnerStarting: (runner) ->
@startTime = new Date() @startTime = new Date()
JHW.stdout.puts("\nRunning Jasmine specs...".bright()) JHW.stdout.puts("\nRunning Jasmine specs...".bright()) if !this.hasError()
reportSpecResults: (spec) -> reportSpecResults: (spec) ->
return if this.hasError() return if this.hasError()

View File

@ -1,16 +1,13 @@
(function() {
window.HeadlessReporterResult = (function() { window.HeadlessReporterResult = (function() {
function HeadlessReporterResult(name, splitName) { function HeadlessReporterResult(name, splitName) {
this.name = name; this.name = name;
this.splitName = splitName; this.splitName = splitName;
this.results = []; this.results = [];
} }
HeadlessReporterResult.prototype.addResult = function(message) { HeadlessReporterResult.prototype.addResult = function(message) {
return this.results.push(message); return this.results.push(message);
}; };
HeadlessReporterResult.prototype.print = function() { HeadlessReporterResult.prototype.print = function() {
var bestChoice, output, result, _i, _len, _ref, _results; var bestChoice, output, result, _i, _len, _ref, _results;
output = this.name.foreground('red'); output = this.name.foreground('red');
@ -18,7 +15,7 @@
if (bestChoice.file) { if (bestChoice.file) {
output += (" (" + bestChoice.file + ":" + bestChoice.lineNumber + ")").foreground('blue'); output += (" (" + bestChoice.file + ":" + bestChoice.lineNumber + ")").foreground('blue');
} }
JHW.stdout.puts("\n\n" + output); JHW.stdout.puts("\n" + output);
_ref = this.results; _ref = this.results;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -28,15 +25,10 @@
output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright(); output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright();
} }
JHW.stdout.puts(" " + output); JHW.stdout.puts(" " + output);
if (result.line != null) { _results.push(result.line != null ? JHW.stdout.puts((" " + result.line).foreground('yellow')) : void 0);
_results.push(JHW.stdout.puts((" " + result.line).foreground('yellow')));
} else {
_results.push(void 0);
}
} }
return _results; return _results;
}; };
HeadlessReporterResult.findSpecLine = function(splitName) { HeadlessReporterResult.findSpecLine = function(splitName) {
var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref; var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref;
bestChoice = { bestChoice = {
@ -57,7 +49,9 @@
for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) { for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) {
line = newLineNumberInfo[_i]; line = newLineNumberInfo[_i];
lastLine = line; lastLine = line;
if (line > lineNumber) break; if (line > lineNumber) {
break;
}
} }
lineNumber = lastLine; lineNumber = lastLine;
} }
@ -73,7 +67,6 @@
} }
return bestChoice; return bestChoice;
}; };
return HeadlessReporterResult; return HeadlessReporterResult;
})(); })();
}).call(this);

View File

@ -1,6 +1,5 @@
(function() { (function() {
var code, method, _ref; var code, method, _ref;
window.Intense = { window.Intense = {
colors: { colors: {
black: 0, black: 0,
@ -30,15 +29,15 @@
}, },
useColors: true, useColors: true,
moveBack: function(count) { moveBack: function(count) {
if (count == null) count = 1; if (count == null) {
count = 1;
}
return "\033[" + count + "D"; return "\033[" + count + "D";
} }
}; };
_ref = Intense.methods; _ref = Intense.methods;
for (method in _ref) { for (method in _ref) {
code = _ref[method]; code = _ref[method];
String.prototype[method] = code; String.prototype[method] = code;
} }
}).call(this); }).call(this);

View File

@ -1,11 +1,9 @@
(function() { (function() {
var generator, getSplitName, method, pauseAndRun, _i, _len, _ref; var generator, getSplitName, method, pauseAndRun, _i, _len, _ref;
var __slice = Array.prototype.slice; var __slice = Array.prototype.slice;
if (!(typeof jasmine !== "undefined" && jasmine !== null)) { if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
throw new Error("jasmine not laoded!"); throw new Error("jasmine not laoded!");
} }
if (window.JHW) { if (window.JHW) {
getSplitName = function(parts) { getSplitName = function(parts) {
parts.push(String(this.description).replace(/[\n\r]/g, ' ')); parts.push(String(this.description).replace(/[\n\r]/g, ' '));
@ -112,11 +110,7 @@
_results = []; _results = [];
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
reporter = _ref2[_j]; reporter = _ref2[_j];
if (reporter[method] != null) { _results.push(reporter[method] != null ? reporter[method].apply(reporter, args) : void 0);
_results.push(reporter[method].apply(reporter, args));
} else {
_results.push(void 0);
}
} }
return _results; return _results;
}; };
@ -125,5 +119,4 @@
} }
} }
} }
}).call(this); }).call(this);

View File

@ -1,10 +1,9 @@
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
if (!(typeof jasmine !== "undefined" && jasmine !== null)) { if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
throw new Error("jasmine not loaded!"); throw new Error("jasmine not loaded!");
} }
jasmine.HeadlessConsoleReporter = (function() { jasmine.HeadlessConsoleReporter = (function() {
function HeadlessConsoleReporter(callback) { function HeadlessConsoleReporter(callback) {
this.callback = callback != null ? callback : null; this.callback = callback != null ? callback : null;
this.results = []; this.results = [];
@ -14,10 +13,11 @@
this.position = 0; this.position = 0;
this.positions = "|/-\\"; this.positions = "|/-\\";
} }
HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) { HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) {
var output, result, resultLine, runtime, _i, _len, _ref; var output, result, resultLine, runtime, _i, _len, _ref;
if (this.hasError()) return; if (this.hasError()) {
return;
}
runtime = (new Date() - this.startTime) / 1000.0; runtime = (new Date() - this.startTime) / 1000.0;
JHW.stdout.print("\n"); JHW.stdout.print("\n");
resultLine = this._formatResultLine(runtime); resultLine = this._formatResultLine(runtime);
@ -34,18 +34,22 @@
result = _ref[_i]; result = _ref[_i];
result.print(); result.print();
} }
if (window.JHW) window.onbeforeunload = null; if (window.JHW) {
window.onbeforeunload = null;
}
return JHW.finishSuite(); return JHW.finishSuite();
}; };
HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) { HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) {
this.startTime = new Date(); this.startTime = new Date();
return JHW.stdout.puts("\nRunning Jasmine specs...".bright()); if (!this.hasError()) {
return JHW.stdout.puts("\nRunning Jasmine specs...".bright());
}
}; };
HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) { HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) {
var failureResult, foundLine, result, results, testCount, _i, _len, _ref; var failureResult, foundLine, result, results, testCount, _i, _len, _ref;
if (this.hasError()) return; if (this.hasError()) {
return;
}
JHW.ping(); JHW.ping();
results = spec.results(); results = spec.results();
this.length++; this.length++;
@ -72,37 +76,35 @@
return this.results.push(failureResult); return this.results.push(failureResult);
} }
}; };
HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) { HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) {
if (this.hasError()) { if (this.hasError()) {
spec.finish(); spec.finish();
return spec.suite.finish(); return spec.suite.finish();
} }
}; };
HeadlessConsoleReporter.prototype.reportSpecWaiting = function() { HeadlessConsoleReporter.prototype.reportSpecWaiting = function() {
var first, runner; var first, runner;
var _this = this;
runner = null; runner = null;
if (!this.timer) { if (!this.timer) {
this.timer = true; this.timer = true;
first = true; first = true;
runner = function() { runner = __bind(function() {
return _this.timer = setTimeout(function() { return this.timer = setTimeout(__bind(function() {
if (_this.timer) { if (this.timer) {
if (!first) JHW.stdout.print(Intense.moveBack()); if (!first) {
JHW.stdout.print(_this.positions.substr(_this.position, 1).foreground('yellow')); JHW.stdout.print(Intense.moveBack());
_this.position += 1; }
_this.position %= _this.positions.length; JHW.stdout.print(this.positions.substr(this.position, 1).foreground('yellow'));
this.position += 1;
this.position %= this.positions.length;
first = false; first = false;
return runner(); return runner();
} }
}, 750); }, this), 750);
}; }, this);
return runner(); return runner();
} }
}; };
HeadlessConsoleReporter.prototype.reportSpecRunning = function() { HeadlessConsoleReporter.prototype.reportSpecRunning = function() {
if (this.timer) { if (this.timer) {
clearTimeout(this.timer); clearTimeout(this.timer);
@ -110,13 +112,10 @@
return JHW.stdout.print(Intense.moveBack()); return JHW.stdout.print(Intense.moveBack());
} }
}; };
HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {}; HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {};
HeadlessConsoleReporter.prototype.hasError = function() { HeadlessConsoleReporter.prototype.hasError = function() {
return JHW._hasErrors; return JHW._hasErrors;
}; };
HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) { HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) {
var line; var line;
line = []; line = [];
@ -128,7 +127,6 @@
line.push((runtime === 1.0 ? "sec" : "secs") + '.'); line.push((runtime === 1.0 ? "sec" : "secs") + '.');
return line.join(' '); return line.join(' ');
}; };
return HeadlessConsoleReporter; return HeadlessConsoleReporter;
})(); })();
}).call(this);

View File

@ -1,6 +1,5 @@
(function() { (function() {
var createHandle, handle, _i, _len, _ref; var createHandle, handle, _i, _len, _ref;
if (window.JHW) { if (window.JHW) {
window.console = { window.console = {
log: function(data) { log: function(data) {
@ -41,7 +40,9 @@
e = e || window.event; e = e || window.event;
JHW.hasError(); JHW.hasError();
JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.'); JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.');
if (e) e.returnValue = 'string'; if (e) {
e.returnValue = 'string';
}
return 'string'; return 'string';
}; };
window.confirm = function(message) { window.confirm = function(message) {
@ -83,9 +84,6 @@
return JHW.stdout.puts(msg); return JHW.stdout.puts(msg);
}; };
} }
window.CoffeeScriptToFilename = {}; window.CoffeeScriptToFilename = {};
window.CSTF = window.CoffeeScriptToFilename; window.CSTF = window.CoffeeScriptToFilename;
}).call(this); }).call(this);