wow that was a pain
This commit is contained in:
parent
f070f042f2
commit
8b36430ba9
@ -7,33 +7,68 @@ Flowerbox =
|
|||||||
debug: false
|
debug: false
|
||||||
ping: ->
|
ping: ->
|
||||||
Flowerbox.contact('ping')
|
Flowerbox.contact('ping')
|
||||||
working: false
|
|
||||||
|
contactQueue: []
|
||||||
|
|
||||||
contact: (url, data...) ->
|
contact: (url, data...) ->
|
||||||
if !Flowerbox.debug
|
if !Flowerbox.debug
|
||||||
Flowerbox.contactQueue ||= []
|
|
||||||
|
|
||||||
Flowerbox.contactQueue.push([url, data])
|
Flowerbox.contactQueue.push([url, data])
|
||||||
Flowerbox.workOffQueue()
|
|
||||||
|
|
||||||
workOffQueue: ->
|
queueIndex: 0
|
||||||
if !Flowerbox.working
|
delay: 40
|
||||||
Flowerbox.working = true
|
started: false
|
||||||
Flowerbox.doWorkOffQueue()
|
done: false
|
||||||
|
|
||||||
doWorkOffQueue: ->
|
onQueueStateChange: ->
|
||||||
|
|
||||||
|
queueRunner: ->
|
||||||
|
Flowerbox.onQueueStateChange("checking queue")
|
||||||
if Flowerbox.contactQueue.length > 0
|
if Flowerbox.contactQueue.length > 0
|
||||||
[ url, data ] = Flowerbox.contactQueue.shift()
|
Flowerbox.started = true
|
||||||
|
|
||||||
|
info = Flowerbox.contactQueue.shift()
|
||||||
|
|
||||||
|
[ url, data ] = info
|
||||||
|
|
||||||
xhr = new XMLHttpRequest()
|
xhr = new XMLHttpRequest()
|
||||||
xhr.open("POST", Flowerbox.baseUrl + url, true)
|
xhr.open("POST", Flowerbox.baseUrl + url, true)
|
||||||
xhr.setRequestHeader("Accept", "application/json")
|
xhr.setRequestHeader("Accept", "application/json")
|
||||||
|
done = false
|
||||||
xhr.onreadystatechange = ->
|
xhr.onreadystatechange = ->
|
||||||
if @readyState == @DONE
|
if xhr.readyState == 4
|
||||||
Flowerbox.doWorkOffQueue()
|
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))
|
xhr.send(JSON.stringify(data))
|
||||||
else
|
else
|
||||||
Flowerbox.working = false
|
Flowerbox.startQueueRunner()
|
||||||
|
|
||||||
|
startQueueRunner: ->
|
||||||
|
setTimeout(
|
||||||
|
->
|
||||||
|
Flowerbox.queueRunner()
|
||||||
|
, Flowerbox.delay
|
||||||
|
)
|
||||||
|
|
||||||
fail: ->
|
fail: ->
|
||||||
|
|
||||||
|
@ -33,3 +33,25 @@ Flowerbox.only = (envs..., code) ->
|
|||||||
if Flowerbox.environment == env
|
if Flowerbox.environment == env
|
||||||
describe("only in #{envs.join(', ')}", code)
|
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)
|
||||||
|
|
||||||
|
@ -15,19 +15,34 @@ class jasmine.FlowerboxReporter
|
|||||||
@time = (new Date()).getTime()
|
@time = (new Date()).getTime()
|
||||||
|
|
||||||
Flowerbox.contact("starting")
|
Flowerbox.contact("starting")
|
||||||
|
|
||||||
reportSpecStarting: (spec) ->
|
reportSpecStarting: (spec) ->
|
||||||
Flowerbox.contact("start_test", spec.description)
|
Flowerbox.contact("start_test", spec.getSpecSplitName().join(" "))
|
||||||
|
|
||||||
if spec.description == 'encountered a declaration exception'
|
if spec.description == 'encountered a declaration exception'
|
||||||
Flowerbox.contact("finish_test", this.buildResult(spec, status: Flowerbox.Result.FAILURE))
|
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) ->
|
reportSpecResults: (spec) ->
|
||||||
|
this.reportSpecRunning() if @paused
|
||||||
|
|
||||||
result = this.buildResult(spec)
|
result = this.buildResult(spec)
|
||||||
|
|
||||||
for item in spec.results().items_
|
for item in spec.results().items_
|
||||||
if !item.passed_
|
if !item.passed_
|
||||||
result.status = Flowerbox.Result.FAILURE
|
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)
|
result.failures.push(failure)
|
||||||
|
|
||||||
|
@ -20,34 +20,49 @@ module Flowerbox
|
|||||||
JSON.parse(request.body.string)
|
JSON.parse(request.body.string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.empty_post(*args, &block)
|
def self.command(*args, &block)
|
||||||
post(*args) do
|
url, args = args
|
||||||
|
url = "/#{url}"
|
||||||
|
|
||||||
|
post(url, *args) do
|
||||||
instance_eval(&block)
|
instance_eval(&block)
|
||||||
|
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
empty_post '/results' do
|
command :results do
|
||||||
runner.finish!(data.flatten.first)
|
runner.finish!(data.flatten.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
empty_post '/start_test' do
|
command :start_test do
|
||||||
runner.add_tests(data.flatten)
|
runner.add_tests(data.flatten)
|
||||||
end
|
end
|
||||||
|
|
||||||
empty_post '/finish_test' do
|
command :finish_test do
|
||||||
runner.add_results(data.flatten)
|
runner.add_results(data.flatten)
|
||||||
end
|
end
|
||||||
|
|
||||||
empty_post '/log' do
|
command :log do
|
||||||
runner.log(data.first)
|
runner.log(data.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
empty_post '/ping' do
|
command :ping do
|
||||||
runner.ping
|
runner.ping
|
||||||
end
|
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|
|
get %r{^/__F__/(.*)$} do |file|
|
||||||
asset = sprockets.asset_for(file, :bundle => false)
|
asset = sprockets.asset_for(file, :bundle => false)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ module Flowerbox::Result
|
|||||||
def first_local_stack
|
def first_local_stack
|
||||||
@data['stack'][1..-1].find do |line|
|
@data['stack'][1..-1].find do |line|
|
||||||
!system_files.any? { |file| line[%r{\(#{file}}] }
|
!system_files.any? { |file| line[%r{\(#{file}}] }
|
||||||
end || @data['stack'][1]
|
end || @data['stack'][1] || ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Flowerbox
|
|||||||
|
|
||||||
attr_accessor :results
|
attr_accessor :results
|
||||||
|
|
||||||
MAX_COUNT = 30
|
MAX_COUNT = 50
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@results = ResultSet.new
|
@results = ResultSet.new
|
||||||
@ -13,9 +13,15 @@ module Flowerbox
|
|||||||
|
|
||||||
def ensure_alive
|
def ensure_alive
|
||||||
while @count < MAX_COUNT && !finished?
|
while @count < MAX_COUNT && !finished?
|
||||||
@count += 1
|
@count += 1 if @timer_running
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !finished?
|
||||||
|
puts tests.flatten.join("\n").foreground(:red)
|
||||||
|
cleanup
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup(sprockets, spec_files, options)
|
def setup(sprockets, spec_files, options)
|
||||||
@ -30,6 +36,7 @@ module Flowerbox
|
|||||||
setup(*args)
|
setup(*args)
|
||||||
|
|
||||||
@count = 0
|
@count = 0
|
||||||
|
@timer_running = true
|
||||||
|
|
||||||
puts "Flowerbox running your #{Flowerbox.test_environment.name} tests on #{console_name}..."
|
puts "Flowerbox running your #{Flowerbox.test_environment.name} tests on #{console_name}..."
|
||||||
|
|
||||||
@ -49,6 +56,15 @@ module Flowerbox
|
|||||||
def configure
|
def configure
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pause_timer
|
||||||
|
@timer_running = false
|
||||||
|
@count = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def unpause_timer
|
||||||
|
@timer_running = true
|
||||||
|
end
|
||||||
|
|
||||||
def debug?
|
def debug?
|
||||||
options[:debug] == true
|
options[:debug] == true
|
||||||
end
|
end
|
||||||
@ -97,6 +113,8 @@ module Flowerbox
|
|||||||
def add_tests(new_tests)
|
def add_tests(new_tests)
|
||||||
tests << new_tests
|
tests << new_tests
|
||||||
|
|
||||||
|
puts new_tests.flatten if options[:verbose_server]
|
||||||
|
|
||||||
@count = 0
|
@count = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -109,6 +127,8 @@ module Flowerbox
|
|||||||
|
|
||||||
results.print_progress
|
results.print_progress
|
||||||
|
|
||||||
|
@count = 0
|
||||||
|
|
||||||
@results << results
|
@results << results
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,14 +22,13 @@ module Flowerbox
|
|||||||
|
|
||||||
def configured?
|
def configured?
|
||||||
File.directory?(File.join(Dir.pwd, 'node_modules/jsdom')) &&
|
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/XMLHttpRequest'))
|
||||||
File.directory?(File.join(Dir.pwd, 'node_modules/cucumber'))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup ; end
|
def cleanup ; end
|
||||||
|
|
||||||
def configure
|
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
|
end
|
||||||
|
|
||||||
def run(sprockets, spec_files, options)
|
def run(sprockets, spec_files, options)
|
||||||
@ -108,9 +107,19 @@ jsdom.env(
|
|||||||
} else {
|
} else {
|
||||||
#{env}
|
#{env}
|
||||||
|
|
||||||
|
context.Flowerbox.onQueueStateChange = function(msg) {
|
||||||
|
//console.log(msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Flowerbox.startQueueRunner()
|
||||||
|
|
||||||
var waitForFinish;
|
var waitForFinish;
|
||||||
waitForFinish = function() {
|
waitForFinish = function() {
|
||||||
if (context.Flowerbox.working) { process.nextTick(waitForFinish); }
|
if (!context.Flowerbox.started || !context.Flowerbox.done) {
|
||||||
|
process.nextTick(waitForFinish);
|
||||||
|
} else {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
waitForFinish();
|
waitForFinish();
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,18 @@ console.log = function(msg) {
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Flowerbox - #{Flowerbox.test_environment.name} Runner</h1>
|
<h1>Flowerbox - #{Flowerbox.test_environment.name} Runner</h1>
|
||||||
|
<pre id="queue"></pre>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
Flowerbox.environment = '#{name}';
|
Flowerbox.environment = '#{name}';
|
||||||
|
Flowerbox.onQueueStateChange = function(msg) {
|
||||||
|
//document.getElementById('queue').innerHTML = document.getElementById('queue').innerHTML + "\\n" + msg;
|
||||||
|
};
|
||||||
|
|
||||||
var context = this;
|
var context = this;
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
window.addEventListener('DOMContentLoaded', function() {
|
||||||
#{env}
|
#{env}
|
||||||
|
Flowerbox.startQueueRunner()
|
||||||
}, false);
|
}, false);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -26,6 +26,7 @@ if (typeof context != 'undefined' && typeof jasmine == 'undefined') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
jasmine.getEnv().addReporter(new jasmine.FlowerboxReporter());
|
jasmine.getEnv().addReporter(new jasmine.FlowerboxReporter());
|
||||||
|
|
||||||
jasmine.getEnv().execute();
|
jasmine.getEnv().execute();
|
||||||
JS
|
JS
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user