2011-06-16 13:51:49 +00:00
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
require 'coffee-script'
|
|
|
|
require 'rainbow'
|
|
|
|
|
2011-07-20 22:27:20 +00:00
|
|
|
require 'yaml'
|
2011-11-20 18:35:30 +00:00
|
|
|
require 'sprockets'
|
|
|
|
|
2011-07-20 22:27:20 +00:00
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
module Jasmine
|
|
|
|
module Headless
|
|
|
|
class Runner
|
|
|
|
JASMINE_DEFAULTS = {
|
|
|
|
'spec_files' => [ '**/*[sS]pec.js' ],
|
|
|
|
'helpers' => [ 'helpers/**/*.js' ],
|
|
|
|
'spec_dir' => 'spec/javascripts',
|
|
|
|
'src_dir' => nil,
|
|
|
|
'stylesheets' => [],
|
2011-09-12 19:12:58 +00:00
|
|
|
'src_files' => [],
|
|
|
|
'backtrace' => []
|
2011-06-16 13:51:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 20:23:29 +00:00
|
|
|
RUNNER_DIR = File.expand_path('../../../../ext/jasmine-webkit-specrunner', __FILE__)
|
|
|
|
RUNNER = File.join(RUNNER_DIR, 'jasmine-webkit-specrunner')
|
2011-06-16 13:51:49 +00:00
|
|
|
|
2011-06-16 14:11:37 +00:00
|
|
|
attr_reader :options
|
|
|
|
|
2011-11-20 18:35:30 +00:00
|
|
|
class << self
|
|
|
|
def run(options = {})
|
|
|
|
options = Options.new(options) if !options.kind_of?(Options)
|
|
|
|
new(options).run
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options)
|
2011-07-14 20:23:29 +00:00
|
|
|
if !File.file?(RUNNER)
|
|
|
|
$stderr.puts "No runner found, attempting to compile..."
|
|
|
|
Dir.chdir RUNNER_DIR do
|
|
|
|
system %{ruby extconf.rb}
|
|
|
|
end
|
|
|
|
raise NoRunnerError if !File.file?(RUNNER)
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
|
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
2011-10-10 18:11:13 +00:00
|
|
|
def template_writer
|
|
|
|
@template_writer ||= TemplateWriter.new(self)
|
|
|
|
end
|
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
def jasmine_config
|
2011-10-24 15:48:41 +00:00
|
|
|
return @jasmine_config if @jasmine_config
|
2011-08-10 17:11:05 +00:00
|
|
|
|
2011-10-24 15:48:41 +00:00
|
|
|
@jasmine_config = JASMINE_DEFAULTS.dup
|
|
|
|
jasmine_config_data.each do |key, value|
|
|
|
|
@jasmine_config[key] = value if value
|
|
|
|
end
|
|
|
|
@jasmine_config
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def jasmine_command(*targets)
|
|
|
|
[
|
|
|
|
RUNNER,
|
|
|
|
@options[:colors] ? '-c' : nil,
|
|
|
|
@options[:report] ? "-r #{@options[:report]}" : nil,
|
|
|
|
*targets
|
|
|
|
].compact.join(" ")
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2011-09-01 14:39:29 +00:00
|
|
|
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
|
2011-11-21 15:55:37 +00:00
|
|
|
FilesList.reset!
|
2011-09-01 13:38:53 +00:00
|
|
|
|
2011-11-16 20:28:02 +00:00
|
|
|
files_list = Jasmine::Headless::FilesList.new(
|
2011-06-16 13:51:49 +00:00
|
|
|
:config => jasmine_config,
|
2011-11-28 16:47:05 +00:00
|
|
|
:only => @options[:files],
|
|
|
|
:seed => @options[:seed]
|
2011-06-16 13:51:49 +00:00
|
|
|
)
|
|
|
|
|
2011-10-17 15:10:00 +00:00
|
|
|
@_targets = template_writer.write!(files_list)
|
2011-12-02 23:37:14 +00:00
|
|
|
|
2011-10-17 15:10:00 +00:00
|
|
|
run_targets = @_targets.dup
|
2011-12-02 23:37:14 +00:00
|
|
|
|
|
|
|
if run_targets.length == 2
|
|
|
|
if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope?
|
|
|
|
run_targets.pop
|
|
|
|
end
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
|
|
|
|
system jasmine_command(run_targets)
|
2011-11-28 16:47:05 +00:00
|
|
|
|
|
|
|
puts "\nTest ordering seed: --seed #{@options[:seed]}"
|
|
|
|
|
2011-10-17 15:10:00 +00:00
|
|
|
@_status = $?.exitstatus
|
|
|
|
ensure
|
|
|
|
if @_targets && !runner_filename && (@options[:remove_html_file] || (@_status == 0))
|
|
|
|
@_targets.each { |target| FileUtils.rm_f target }
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-10 18:11:13 +00:00
|
|
|
|
|
|
|
def runner_filename
|
2011-10-11 12:55:43 +00:00
|
|
|
options[:runner_output_filename] || begin
|
|
|
|
if (runner_output = jasmine_config['runner_output']) && !runner_output.empty?
|
|
|
|
runner_output
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2011-10-10 18:11:13 +00:00
|
|
|
end
|
2011-10-24 15:48:41 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
def jasmine_config_data
|
|
|
|
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])
|
|
|
|
|
|
|
|
YAML.load_file(@options[:jasmine_config])
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|