show an indicator when wait tests are running, so it doesn't look like the program crashed

This commit is contained in:
John Bintz 2011-11-21 11:33:51 -05:00
parent 9b5729b808
commit 4727ad5b7b
7 changed files with 109 additions and 8 deletions

View File

@ -3,7 +3,6 @@
# watch('file/path') { `command(s)` } # watch('file/path') { `command(s)` }
# #
if false
guard 'coffeescript', :input => 'vendor/assets/coffeescripts', :output => 'vendor/assets/javascripts' guard 'coffeescript', :input => 'vendor/assets/coffeescripts', :output => 'vendor/assets/javascripts'
guard 'shell' do guard 'shell' do
@ -22,7 +21,6 @@ guard 'rspec', :version => 2, :all_on_start => false do
watch(%r{^bin/(.+)}) { |m| "spec/bin/#{m[1]}_spec.rb" } watch(%r{^bin/(.+)}) { |m| "spec/bin/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" } watch('spec/spec_helper.rb') { "spec" }
end end
end
guard 'jasmine-headless-webkit', :all_on_start => false do guard 'jasmine-headless-webkit', :all_on_start => false do
watch(%r{^spec/javascripts/.+_spec\.coffee}) watch(%r{^spec/javascripts/.+_spec\.coffee})

View File

@ -20,6 +20,7 @@ window.Intense = {
else else
this this
useColors: true useColors: true
moveBack: (count = 1) -> "\033[#{count}D"
} }
for method, code of Intense.methods for method, code of Intense.methods

View File

@ -73,11 +73,10 @@ if window.JHW
pauseAndRun = (onComplete) -> pauseAndRun = (onComplete) ->
JHW.timerPause() JHW.timerPause()
if this.env.reporter.reportSpecWaiting jasmine.getEnv().reporter.reportSpecWaiting()
this.env.reporter.reportSpecWaiting(this)
this._execute -> this._execute ->
if this.env.reporter.reportSpecRunning jasmine.getEnv().reporter.reportSpecRunning()
this.env.reporter.reportSpecRunning(this)
JHW.timerDone() JHW.timerDone()
onComplete() onComplete()
@ -92,3 +91,13 @@ if window.JHW
result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()) result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString())
this.addResult_(result) this.addResult_(result)
for method in [ "reportSpecWaiting", "reportSpecRunning" ]
generator = (method) ->
(args...) ->
for reporter in @subReporters_
if reporter[method]?
reporter[method](args...)
jasmine.MultiReporter.prototype[method] = generator(method)

View File

@ -6,6 +6,9 @@ class jasmine.HeadlessConsoleReporter
@results = [] @results = []
@failedCount = 0 @failedCount = 0
@length = 0 @length = 0
@timer = null
@position = 0
@positions = "|/-\\"
reportRunnerResults: (runner) -> reportRunnerResults: (runner) ->
return if this.hasError() return if this.hasError()
@ -67,6 +70,33 @@ class jasmine.HeadlessConsoleReporter
spec.finish() spec.finish()
spec.suite.finish() spec.suite.finish()
reportSpecWaiting: ->
runner = null
if !@timer
@timer = true
first = true
runner = =>
@timer = setTimeout(
=>
if @timer
JHW.stdout.print(Intense.moveBack()) if !first
JHW.stdout.print(@positions.substr(@position, 1).foreground('yellow'))
@position += 1
@position %= @positions.length
first = false
runner()
, 750
)
runner()
reportSpecRunning: ->
if @timer
clearTimeout(@timer)
@timer = null
JHW.stdout.print(Intense.moveBack())
reportSuiteResults: (suite) -> reportSuiteResults: (suite) ->
hasError: -> hasError: ->
JHW._hasErrors JHW._hasErrors

View File

@ -28,7 +28,11 @@
} }
} }
}, },
useColors: true useColors: true,
moveBack: function(count) {
if (count == null) count = 1;
return "\033[" + count + "D";
}
}; };
_ref = Intense.methods; _ref = Intense.methods;

View File

@ -1,5 +1,6 @@
(function() { (function() {
var getSplitName, pauseAndRun; var generator, getSplitName, method, pauseAndRun, _i, _len, _ref;
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!");
@ -85,7 +86,9 @@
jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute; jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute;
pauseAndRun = function(onComplete) { pauseAndRun = function(onComplete) {
JHW.timerPause(); JHW.timerPause();
jasmine.getEnv().reporter.reportSpecWaiting();
return this._execute(function() { return this._execute(function() {
jasmine.getEnv().reporter.reportSpecRunning();
JHW.timerDone(); JHW.timerDone();
return onComplete(); return onComplete();
}); });
@ -98,6 +101,28 @@
result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()); result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString());
return this.addResult_(result); return this.addResult_(result);
}; };
_ref = ["reportSpecWaiting", "reportSpecRunning"];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
method = _ref[_i];
generator = function(method) {
return function() {
var args, reporter, _j, _len2, _ref2, _results;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
_ref2 = this.subReporters_;
_results = [];
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
reporter = _ref2[_j];
if (reporter[method] != null) {
_results.push(reporter[method].apply(reporter, args));
} else {
_results.push(void 0);
}
}
return _results;
};
};
jasmine.MultiReporter.prototype[method] = generator(method);
}
} }
} }

View File

@ -10,6 +10,9 @@
this.results = []; this.results = [];
this.failedCount = 0; this.failedCount = 0;
this.length = 0; this.length = 0;
this.timer = null;
this.position = 0;
this.positions = "|/-\\";
} }
HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) { HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) {
@ -77,6 +80,37 @@
} }
}; };
HeadlessConsoleReporter.prototype.reportSpecWaiting = function() {
var first, runner;
var _this = this;
runner = null;
if (!this.timer) {
this.timer = true;
first = true;
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;
first = false;
return runner();
}
}, 750);
};
return runner();
}
};
HeadlessConsoleReporter.prototype.reportSpecRunning = function() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
return JHW.stdout.print(Intense.moveBack());
}
};
HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {}; HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {};
HeadlessConsoleReporter.prototype.hasError = function() { HeadlessConsoleReporter.prototype.hasError = function() {