wow that was a pain

This commit is contained in:
John Bintz 2012-03-15 11:57:35 -04:00
parent f070f042f2
commit 8b36430ba9
9 changed files with 151 additions and 29 deletions

View File

@ -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: ->

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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();
}

View File

@ -50,13 +50,18 @@ console.log = function(msg) {
</head>
<body>
<h1>Flowerbox - #{Flowerbox.test_environment.name} Runner</h1>
<pre id="queue"></pre>
<script type="text/javascript">
Flowerbox.environment = '#{name}';
Flowerbox.onQueueStateChange = function(msg) {
//document.getElementById('queue').innerHTML = document.getElementById('queue').innerHTML + "\\n" + msg;
};
var context = this;
window.addEventListener('DOMContentLoaded', function() {
#{env}
Flowerbox.startQueueRunner()
}, false);
</script>
</body>

View File

@ -26,6 +26,7 @@ if (typeof context != 'undefined' && typeof jasmine == 'undefined') {
}
jasmine.getEnv().addReporter(new jasmine.FlowerboxReporter());
jasmine.getEnv().execute();
JS
end