From 8b36430ba9add93fc831a25d95501a9e42e9c676 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 15 Mar 2012 11:57:35 -0400 Subject: [PATCH] wow that was a pain --- lib/assets/javascripts/flowerbox.js.coffee | 61 +++++++++++++++---- .../javascripts/flowerbox/jasmine.js.coffee | 22 +++++++ .../flowerbox/jasmine/reporter.js.coffee | 19 +++++- lib/flowerbox/rack.rb | 29 ++++++--- lib/flowerbox/result/failure_message.rb | 2 +- lib/flowerbox/runner/base.rb | 24 +++++++- lib/flowerbox/runner/node.rb | 17 ++++-- lib/flowerbox/runner/selenium.rb | 5 ++ lib/flowerbox/test_environment/jasmine.rb | 1 + 9 files changed, 151 insertions(+), 29 deletions(-) diff --git a/lib/assets/javascripts/flowerbox.js.coffee b/lib/assets/javascripts/flowerbox.js.coffee index c9f5f6c..a72b7a3 100644 --- a/lib/assets/javascripts/flowerbox.js.coffee +++ b/lib/assets/javascripts/flowerbox.js.coffee @@ -7,33 +7,68 @@ Flowerbox = debug: false ping: -> Flowerbox.contact('ping') - working: false + + contactQueue: [] contact: (url, data...) -> if !Flowerbox.debug - Flowerbox.contactQueue ||= [] - Flowerbox.contactQueue.push([url, data]) - Flowerbox.workOffQueue() - workOffQueue: -> - if !Flowerbox.working - Flowerbox.working = true - Flowerbox.doWorkOffQueue() + queueIndex: 0 + delay: 40 + started: false + done: false - doWorkOffQueue: -> + onQueueStateChange: -> + + queueRunner: -> + Flowerbox.onQueueStateChange("checking queue") if Flowerbox.contactQueue.length > 0 - [ url, data ] = Flowerbox.contactQueue.shift() + Flowerbox.started = true + + info = Flowerbox.contactQueue.shift() + + [ url, data ] = info xhr = new XMLHttpRequest() xhr.open("POST", Flowerbox.baseUrl + url, true) xhr.setRequestHeader("Accept", "application/json") + done = false xhr.onreadystatechange = -> - if @readyState == @DONE - Flowerbox.doWorkOffQueue() + if xhr.readyState == 4 + done = true + Flowerbox.onQueueStateChange("done #{url}") + if url == "results" + Flowerbox.onQueueStateChange("finsihed all tests") + Flowerbox.done = true + else + setTimeout( + -> + Flowerbox.queueRunner() + , 1 + ) + Flowerbox.onQueueStateChange("running #{url}") + + setTimeout( + -> + if xhr.readyState != 4 + xhr.abort() + Flowerbox.onQueueStateChange("aborted #{url}, rerunning") + Flowerbox.contactQueue.unshift(info) + Flowerbox.queueRunner() + , Flowerbox.delay * 5 + ) + xhr.send(JSON.stringify(data)) else - Flowerbox.working = false + Flowerbox.startQueueRunner() + + startQueueRunner: -> + setTimeout( + -> + Flowerbox.queueRunner() + , Flowerbox.delay + ) fail: -> diff --git a/lib/assets/javascripts/flowerbox/jasmine.js.coffee b/lib/assets/javascripts/flowerbox/jasmine.js.coffee index ea08ab2..46c1369 100644 --- a/lib/assets/javascripts/flowerbox/jasmine.js.coffee +++ b/lib/assets/javascripts/flowerbox/jasmine.js.coffee @@ -33,3 +33,25 @@ Flowerbox.only = (envs..., code) -> if Flowerbox.environment == env describe("only in #{envs.join(', ')}", code) +jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute +jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute + +pauseAndRun = (onComplete) -> + jasmine.getEnv().reporter.reportSpecWaiting() + + this._execute -> + jasmine.getEnv().reporter.reportSpecRunning() + onComplete() + +jasmine.WaitsBlock.prototype.execute = pauseAndRun +jasmine.WaitsForBlock.prototype.execute = pauseAndRun + +for method in [ "reportSpecWaiting", "reportSpecRunning" ] + generator = (method) -> + (args...) -> + for reporter in @subReporters_ + if reporter[method]? + reporter[method](args...) + + jasmine.MultiReporter.prototype[method] = generator(method) + diff --git a/lib/assets/javascripts/flowerbox/jasmine/reporter.js.coffee b/lib/assets/javascripts/flowerbox/jasmine/reporter.js.coffee index 9e42f45..df098e8 100644 --- a/lib/assets/javascripts/flowerbox/jasmine/reporter.js.coffee +++ b/lib/assets/javascripts/flowerbox/jasmine/reporter.js.coffee @@ -15,19 +15,34 @@ class jasmine.FlowerboxReporter @time = (new Date()).getTime() Flowerbox.contact("starting") + reportSpecStarting: (spec) -> - Flowerbox.contact("start_test", spec.description) + Flowerbox.contact("start_test", spec.getSpecSplitName().join(" ")) if spec.description == 'encountered a declaration exception' Flowerbox.contact("finish_test", this.buildResult(spec, status: Flowerbox.Result.FAILURE)) + reportSpecWaiting: -> + @paused = true + Flowerbox.contact('pause_timer') + + reportSpecRunning: -> + @paused = false + Flowerbox.contact('unpause_timer') + reportSpecResults: (spec) -> + this.reportSpecRunning() if @paused + result = this.buildResult(spec) for item in spec.results().items_ if !item.passed_ result.status = Flowerbox.Result.FAILURE - failure = { runner: Flowerbox.environment, message: item.message, stack: (item.trace.stack || '').split("\n") } + stack = item.trace.stack || [] + if stack.constructor != Array + stack = stack.split("\n") + + failure = { runner: Flowerbox.environment, message: item.message, stack: stack } result.failures.push(failure) diff --git a/lib/flowerbox/rack.rb b/lib/flowerbox/rack.rb index 04475fd..f9ca25d 100644 --- a/lib/flowerbox/rack.rb +++ b/lib/flowerbox/rack.rb @@ -20,34 +20,49 @@ module Flowerbox JSON.parse(request.body.string) end - def self.empty_post(*args, &block) - post(*args) do + def self.command(*args, &block) + url, args = args + url = "/#{url}" + + post(url, *args) do instance_eval(&block) "" end end - empty_post '/results' do + command :results do runner.finish!(data.flatten.first) end - empty_post '/start_test' do + command :start_test do runner.add_tests(data.flatten) end - empty_post '/finish_test' do + command :finish_test do runner.add_results(data.flatten) end - empty_post '/log' do + command :log do runner.log(data.first) end - empty_post '/ping' do + command :ping do runner.ping end + command :pause_timer do + runner.pause_timer + end + + command :unpause_timer do + runner.unpause_timer + end + + command :starting do + + end + get %r{^/__F__/(.*)$} do |file| asset = sprockets.asset_for(file, :bundle => false) diff --git a/lib/flowerbox/result/failure_message.rb b/lib/flowerbox/result/failure_message.rb index 8a06b01..56d1bdc 100644 --- a/lib/flowerbox/result/failure_message.rb +++ b/lib/flowerbox/result/failure_message.rb @@ -27,7 +27,7 @@ module Flowerbox::Result def first_local_stack @data['stack'][1..-1].find do |line| !system_files.any? { |file| line[%r{\(#{file}}] } - end || @data['stack'][1] + end || @data['stack'][1] || '' end end end diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index 8379448..00626b7 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -5,7 +5,7 @@ module Flowerbox attr_accessor :results - MAX_COUNT = 30 + MAX_COUNT = 50 def initialize @results = ResultSet.new @@ -13,9 +13,15 @@ module Flowerbox def ensure_alive while @count < MAX_COUNT && !finished? - @count += 1 + @count += 1 if @timer_running sleep 0.1 end + + if !finished? + puts tests.flatten.join("\n").foreground(:red) + cleanup + exit 1 + end end def setup(sprockets, spec_files, options) @@ -30,6 +36,7 @@ module Flowerbox setup(*args) @count = 0 + @timer_running = true puts "Flowerbox running your #{Flowerbox.test_environment.name} tests on #{console_name}..." @@ -49,6 +56,15 @@ module Flowerbox def configure end + def pause_timer + @timer_running = false + @count = 0 + end + + def unpause_timer + @timer_running = true + end + def debug? options[:debug] == true end @@ -97,6 +113,8 @@ module Flowerbox def add_tests(new_tests) tests << new_tests + puts new_tests.flatten if options[:verbose_server] + @count = 0 end @@ -109,6 +127,8 @@ module Flowerbox results.print_progress + @count = 0 + @results << results end diff --git a/lib/flowerbox/runner/node.rb b/lib/flowerbox/runner/node.rb index e642895..99464d0 100644 --- a/lib/flowerbox/runner/node.rb +++ b/lib/flowerbox/runner/node.rb @@ -22,14 +22,13 @@ module Flowerbox def configured? File.directory?(File.join(Dir.pwd, 'node_modules/jsdom')) && - File.directory?(File.join(Dir.pwd, 'node_modules/XMLHttpRequest')) && - File.directory?(File.join(Dir.pwd, 'node_modules/cucumber')) + File.directory?(File.join(Dir.pwd, 'node_modules/XMLHttpRequest')) end def cleanup ; end def configure - system %{bash -c "mkdir -p node_modules && npm link jsdom && npm link xmlhttprequest && npm link cucumber"} + system %{bash -c "mkdir -p node_modules && npm link jsdom && npm link xmlhttprequest"} end def run(sprockets, spec_files, options) @@ -108,9 +107,19 @@ jsdom.env( } else { #{env} + context.Flowerbox.onQueueStateChange = function(msg) { + //console.log(msg); + }; + + context.Flowerbox.startQueueRunner() + var waitForFinish; waitForFinish = function() { - if (context.Flowerbox.working) { process.nextTick(waitForFinish); } + if (!context.Flowerbox.started || !context.Flowerbox.done) { + process.nextTick(waitForFinish); + } else { + process.exit(0); + } }; waitForFinish(); } diff --git a/lib/flowerbox/runner/selenium.rb b/lib/flowerbox/runner/selenium.rb index 8828ab4..4a8c01e 100644 --- a/lib/flowerbox/runner/selenium.rb +++ b/lib/flowerbox/runner/selenium.rb @@ -50,13 +50,18 @@ console.log = function(msg) {

Flowerbox - #{Flowerbox.test_environment.name} Runner

+

     
   
diff --git a/lib/flowerbox/test_environment/jasmine.rb b/lib/flowerbox/test_environment/jasmine.rb
index 6bfadd0..23b987e 100644
--- a/lib/flowerbox/test_environment/jasmine.rb
+++ b/lib/flowerbox/test_environment/jasmine.rb
@@ -26,6 +26,7 @@ if (typeof context != 'undefined' && typeof jasmine == 'undefined') {
 }
 
 jasmine.getEnv().addReporter(new jasmine.FlowerboxReporter());
+
 jasmine.getEnv().execute();
 JS
       end