diff --git a/flowerbox.gemspec b/flowerbox.gemspec index 75adbe7..2423b1b 100644 --- a/flowerbox.gemspec +++ b/flowerbox.gemspec @@ -33,5 +33,6 @@ Gem::Specification.new do |gem| gem.add_dependency 'sprockets' gem.add_dependency 'sprockets-vendor_gems' gem.add_dependency 'thin' + gem.add_dependency 'em-websocket' end diff --git a/lib/assets/javascripts/flowerbox.js.coffee b/lib/assets/javascripts/flowerbox.js.coffee index ebbd648..ecc8c6e 100644 --- a/lib/assets/javascripts/flowerbox.js.coffee +++ b/lib/assets/javascripts/flowerbox.js.coffee @@ -3,77 +3,18 @@ #= require flowerbox/exception # Flowerbox = - baseUrl: '/' debug: false ping: -> Flowerbox.contact('ping') - contactQueue: [] - contact: (url, data...) -> + Flowerbox.started = true if !Flowerbox.debug - Flowerbox.contactQueue.push([url, data]) + Flowerbox.socket.send(JSON.stringify([ url, data ])) + Flowerbox.done = true if url == 'results' - queueIndex: 0 - delay: 40 started: false done: false - xhrObjects: {} - - onQueueStateChange: -> - - queueRunner: (failsafe = 5) -> - Flowerbox.onQueueStateChange("checking queue") - if Flowerbox.contactQueue.length > 0 - 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 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) - - if failsafe > 0 - failsafe -= 1 - Flowerbox.queueRunner(failsafe) - , Flowerbox.delay * 5 - ) - - xhr.send(JSON.stringify(data)) - else - Flowerbox.startQueueRunner() - - startQueueRunner: -> - setTimeout( - -> - Flowerbox.queueRunner() - , Flowerbox.delay - ) - fail: -> diff --git a/lib/flowerbox/rack.rb b/lib/flowerbox/rack.rb index 060bf80..70dd28d 100644 --- a/lib/flowerbox/rack.rb +++ b/lib/flowerbox/rack.rb @@ -48,19 +48,15 @@ module Flowerbox end 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 - runner.did_start! end get %r{^/__F__/(.*)$} do |file| diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index 84e1167..dc22a33 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -140,7 +140,7 @@ module Flowerbox server_options[:logging] = true if options[:verbose_server] server_options[:port] = Flowerbox.port - Flowerbox.server = Flowerbox::Server.new(server_options) + Flowerbox.server = Flowerbox::Server.new(self, server_options) end def log(message) diff --git a/lib/flowerbox/runner/node.rb b/lib/flowerbox/runner/node.rb index f0fc59b..e83206b 100644 --- a/lib/flowerbox/runner/node.rb +++ b/lib/flowerbox/runner/node.rb @@ -22,13 +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/ws')) end def cleanup ; end def configure - system %{bash -c "mkdir -p node_modules && npm link jsdom && npm link xmlhttprequest"} + system %{bash -c "mkdir -p node_modules && npm link jsdom && npm link ws"} end def run(sprockets, spec_files, options) @@ -53,7 +53,7 @@ var fs = require('fs'), vm = require('vm'), http = require('http'), jsdom = require('jsdom'), - xhr = require('xmlhttprequest') + ws = require('ws') // expand the sandbox a bit var context = function() {}; @@ -62,7 +62,7 @@ for (method in global) { context[method] = global[method]; } jsdom.env( "