a ton more cowboy hacking
This commit is contained in:
parent
a39daffdbb
commit
7a7c5debc4
@ -6,9 +6,10 @@ require 'thor'
|
|||||||
class Flowerbox::CLI < Thor
|
class Flowerbox::CLI < Thor
|
||||||
desc "test DIR", "Run the specs found in spec dir, loading spec_helper.rb for configuration details"
|
desc "test DIR", "Run the specs found in spec dir, loading spec_helper.rb for configuration details"
|
||||||
method_options :pwd => :string
|
method_options :pwd => :string
|
||||||
|
method_options :runners => :string
|
||||||
def test(dir)
|
def test(dir)
|
||||||
Dir.chdir(pwd) do
|
Dir.chdir(pwd) do
|
||||||
exit Flowerbox.run(dir)
|
exit Flowerbox.run(dir, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,4 +4,4 @@ Flowerbox =
|
|||||||
xhr = new XMLHttpRequest()
|
xhr = new XMLHttpRequest()
|
||||||
xhr.open("POST", Flowerbox.baseUrl + url, false)
|
xhr.open("POST", Flowerbox.baseUrl + url, false)
|
||||||
xhr.send(JSON.stringify(data))
|
xhr.send(JSON.stringify(data))
|
||||||
|
fail: ->
|
||||||
|
@ -25,3 +25,8 @@ jasmine.Spec.beforeAddMatcherResult = ->
|
|||||||
jasmine.Spec.beforeAddMatcherResult().push (spec) ->
|
jasmine.Spec.beforeAddMatcherResult().push (spec) ->
|
||||||
@splitName = spec.getSpecSplitName()
|
@splitName = spec.getSpecSplitName()
|
||||||
|
|
||||||
|
Flowerbox.only = (envs..., code) ->
|
||||||
|
for env in envs
|
||||||
|
if Flowerbox.environment == env
|
||||||
|
describe("only in #{envs.join(', ')}", code)
|
||||||
|
|
||||||
|
@ -9,3 +9,4 @@ jasmine.Spec.beforeAddMatcherResult().push ->
|
|||||||
|
|
||||||
Error.prepareStackTrace = Error.prepareStackTrace_
|
Error.prepareStackTrace = Error.prepareStackTrace_
|
||||||
|
|
||||||
|
Flowerbox.fail = -> process.exit(1)
|
||||||
|
@ -5,6 +5,12 @@ class jasmine.FlowerboxReporter
|
|||||||
Flowerbox.contact("starting")
|
Flowerbox.contact("starting")
|
||||||
reportSpecStarting: (spec) ->
|
reportSpecStarting: (spec) ->
|
||||||
Flowerbox.contact("start_test", spec.description)
|
Flowerbox.contact("start_test", spec.description)
|
||||||
|
|
||||||
|
if spec.description == 'encountered a declaration exception'
|
||||||
|
Flowerbox.contact("finish_test", spec.description, { trace: { stack: [ spec.description ] } })
|
||||||
|
Flowerbox.contact("results", 0)
|
||||||
|
Flowerbox.fail() if Flowerbox.fail?
|
||||||
|
|
||||||
reportSpecResults: (spec) ->
|
reportSpecResults: (spec) ->
|
||||||
failures = []
|
failures = []
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ module Flowerbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run_with(*whats)
|
def run_with(*whats)
|
||||||
self.runner_environment = whats.collect { |what| Flowerbox::Runner.for(what) }
|
self.runner_environment = whats.flatten.collect { |what| Flowerbox::Runner.for(what.to_s) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def path
|
def path
|
||||||
@ -62,9 +62,13 @@ module Flowerbox
|
|||||||
@bare_coffeescript ||= true
|
@bare_coffeescript ||= true
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(dir)
|
def run(dir, options = {})
|
||||||
load File.join(dir, 'spec_helper.rb')
|
load File.join(dir, 'spec_helper.rb')
|
||||||
|
|
||||||
|
if options[:runners]
|
||||||
|
Flowerbox.run_with(options[:runners].split(','))
|
||||||
|
end
|
||||||
|
|
||||||
require 'coffee_script'
|
require 'coffee_script'
|
||||||
require 'tilt/coffee'
|
require 'tilt/coffee'
|
||||||
|
|
||||||
@ -73,7 +77,7 @@ module Flowerbox
|
|||||||
result_set = ResultSet.new
|
result_set = ResultSet.new
|
||||||
|
|
||||||
Flowerbox.runner_environment.each do |env|
|
Flowerbox.runner_environment.each do |env|
|
||||||
result_set << env.run(build_sprockets_for(dir))
|
result_set << env.run(build_sprockets_for(dir), spec_files_for(dir))
|
||||||
end
|
end
|
||||||
|
|
||||||
result_set.print
|
result_set.print
|
||||||
@ -95,8 +99,6 @@ module Flowerbox
|
|||||||
|
|
||||||
Flowerbox.test_environment.inject_into(sprockets)
|
Flowerbox.test_environment.inject_into(sprockets)
|
||||||
|
|
||||||
spec_files_for(dir).each { |file| sprockets.add(file) }
|
|
||||||
|
|
||||||
sprockets
|
sprockets
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
module Flowerbox
|
module Flowerbox
|
||||||
class Exception < Result
|
class Exception < Result
|
||||||
attr_reader :message
|
attr_reader :name
|
||||||
|
|
||||||
def initialize(message)
|
def initialize(name)
|
||||||
@message = message
|
@name = name
|
||||||
end
|
end
|
||||||
|
|
||||||
def print
|
def print
|
||||||
puts message
|
puts "[#{runners.join(',')}] #{name}"
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,10 +6,6 @@ module Flowerbox
|
|||||||
@name, @message, @file = name, message, file
|
@name, @message, @file = name, message, file
|
||||||
end
|
end
|
||||||
|
|
||||||
def runners
|
|
||||||
@runners ||= []
|
|
||||||
end
|
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
@name == other.name && @message == other.message
|
@name == other.name && @message == other.message
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ module Flowerbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
empty_post '/start_test' do
|
empty_post '/start_test' do
|
||||||
runner.tests << data.flatten
|
runner.add_tests(data.flatten)
|
||||||
end
|
end
|
||||||
|
|
||||||
empty_post '/finish_test' do
|
empty_post '/finish_test' do
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
module Flowerbox
|
module Flowerbox
|
||||||
class Result
|
class Result
|
||||||
|
def runners
|
||||||
|
@runners ||= []
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ module Flowerbox
|
|||||||
Failure.new(name, failure['message'], failure['trace']['stack'].first)
|
Failure.new(name, failure['message'], failure['trace']['stack'].first)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Exception.new(result_data['trace']['stack'])
|
Exception.new(result_data.first['trace']['stack'])
|
||||||
end
|
end
|
||||||
end.flatten
|
end.flatten
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
module Flowerbox
|
module Flowerbox
|
||||||
module Runner
|
module Runner
|
||||||
class Base
|
class Base
|
||||||
attr_reader :sprockets
|
attr_reader :sprockets, :spec_files
|
||||||
|
|
||||||
attr_accessor :time, :results
|
attr_accessor :time, :results
|
||||||
|
|
||||||
def run(sprockets)
|
def run(sprockets, spec_files)
|
||||||
@sprockets = sprockets
|
@sprockets = sprockets
|
||||||
|
@spec_files = spec_files
|
||||||
|
|
||||||
puts "Flowerbox running your #{Flowerbox.test_environment.name} tests on #{name}..."
|
puts "Flowerbox running your #{Flowerbox.test_environment.name} tests on #{name}..."
|
||||||
|
|
||||||
@ -46,6 +47,10 @@ module Flowerbox
|
|||||||
@tests ||= []
|
@tests ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_tests(new_tests)
|
||||||
|
tests << new_tests
|
||||||
|
end
|
||||||
|
|
||||||
def failures
|
def failures
|
||||||
@failures ||= []
|
@failures ||= []
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,7 @@ module Flowerbox
|
|||||||
:node
|
:node
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(sprockets)
|
def run(sprockets, spec_files)
|
||||||
super do
|
super do
|
||||||
begin
|
begin
|
||||||
file = File.join(Dir.pwd, ".node-tmp.#{Time.now.to_i}.js")
|
file = File.join(Dir.pwd, ".node-tmp.#{Time.now.to_i}.js")
|
||||||
@ -30,6 +30,7 @@ module Flowerbox
|
|||||||
env = start_test_environment
|
env = start_test_environment
|
||||||
|
|
||||||
<<-JS
|
<<-JS
|
||||||
|
// whoa node
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
vm = require('vm'),
|
vm = require('vm'),
|
||||||
http = require('http'),
|
http = require('http'),
|
||||||
@ -45,6 +46,8 @@ jsdom.env(
|
|||||||
context.window = window;
|
context.window = window;
|
||||||
context.XMLHttpRequest = xhr.XMLHttpRequest;
|
context.XMLHttpRequest = xhr.XMLHttpRequest;
|
||||||
|
|
||||||
|
var gotFlowerbox = false;
|
||||||
|
|
||||||
var files = #{sprockets.files.to_json};
|
var files = #{sprockets.files.to_json};
|
||||||
var fileRunner = function() {
|
var fileRunner = function() {
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
@ -71,8 +74,11 @@ jsdom.env(
|
|||||||
if (!context[thing]) { context[thing] = window[thing] }
|
if (!context[thing]) { context[thing] = window[thing] }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.Flowerbox) {
|
if (!gotFlowerbox && context.Flowerbox) {
|
||||||
context.Flowerbox.baseUrl = "http://localhost:#{server.port}/";
|
context.Flowerbox.baseUrl = "http://localhost:#{server.port}/";
|
||||||
|
context.Flowerbox.environment = 'node';
|
||||||
|
|
||||||
|
gotFlowerbox = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileRunner();
|
fileRunner();
|
||||||
@ -92,5 +98,3 @@ JS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Flowerbox.runner_environment = Flowerbox::Runner::Node.new
|
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ module Flowerbox
|
|||||||
:selenium
|
:selenium
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(sprockets)
|
def run(sprockets, spec_files)
|
||||||
super do
|
super do
|
||||||
begin
|
begin
|
||||||
selenium = ::Selenium::WebDriver.for(browser)
|
selenium = ::Selenium::WebDriver.for(browser)
|
||||||
|
@ -20,6 +20,8 @@ module Flowerbox
|
|||||||
@sprockets.add("flowerbox/jasmine")
|
@sprockets.add("flowerbox/jasmine")
|
||||||
@sprockets.add("flowerbox/jasmine/#{runner.type}")
|
@sprockets.add("flowerbox/jasmine/#{runner.type}")
|
||||||
|
|
||||||
|
runner.spec_files.each { |file| @sprockets.add(file) }
|
||||||
|
|
||||||
case runner.type
|
case runner.type
|
||||||
when :node
|
when :node
|
||||||
<<-JS
|
<<-JS
|
||||||
|
Loading…
Reference in New Issue
Block a user