2011-06-16 13:51:49 +00:00
|
|
|
require 'forwardable'
|
2011-06-19 19:08:18 +00:00
|
|
|
require 'getoptlong'
|
2011-06-16 13:51:49 +00:00
|
|
|
|
|
|
|
module Jasmine
|
|
|
|
module Headless
|
|
|
|
class Options
|
|
|
|
extend Forwardable
|
|
|
|
|
|
|
|
def_delegators :@options, :[], :[]=
|
|
|
|
|
|
|
|
DEFAULT_OPTIONS = {
|
|
|
|
:colors => false,
|
|
|
|
:remove_html_file => true,
|
2011-10-10 18:11:13 +00:00
|
|
|
:runner_output_filename => false,
|
2011-06-16 13:51:49 +00:00
|
|
|
:jasmine_config => 'spec/javascripts/support/jasmine.yml',
|
2011-08-22 17:26:48 +00:00
|
|
|
:do_list => false,
|
2011-06-16 13:51:49 +00:00
|
|
|
:full_run => true,
|
2011-09-01 13:38:53 +00:00
|
|
|
:enable_cache => true,
|
2011-12-29 14:32:27 +00:00
|
|
|
:files => [],
|
2012-01-11 13:44:28 +00:00
|
|
|
:reporters => [ [ 'Console' ] ],
|
|
|
|
:quiet => false
|
2011-06-16 13:51:49 +00:00
|
|
|
}
|
|
|
|
|
2011-08-24 00:07:05 +00:00
|
|
|
DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit')
|
2011-10-16 15:05:35 +00:00
|
|
|
GLOBAL_DEFAULTS_FILE = File.expand_path('~/.jasmine-headless-webkit')
|
2011-06-16 13:51:49 +00:00
|
|
|
|
2011-12-29 23:37:23 +00:00
|
|
|
REPORT_DEPRECATED_MESSAGE = "--report is deprecated. Use --format HeadlessFileReporter --out <filename>"
|
|
|
|
|
2011-06-16 13:51:49 +00:00
|
|
|
def self.from_command_line
|
|
|
|
options = new
|
|
|
|
options.process_command_line_args
|
|
|
|
options[:files] = ARGV
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(opts = {})
|
2011-06-16 23:38:45 +00:00
|
|
|
@options = DEFAULT_OPTIONS.dup
|
2011-11-28 16:52:33 +00:00
|
|
|
srand
|
|
|
|
@options[:seed] = rand(10000)
|
2011-08-24 00:07:05 +00:00
|
|
|
read_defaults_files
|
2012-01-11 13:44:28 +00:00
|
|
|
|
2011-06-16 23:38:45 +00:00
|
|
|
opts.each { |k, v| @options[k] = v if v }
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_option(*args)
|
|
|
|
opt, arg = args.flatten[0..1]
|
|
|
|
|
|
|
|
case opt
|
|
|
|
when '--colors', '-c'
|
|
|
|
@options[:colors] = true
|
|
|
|
when '--no-colors', '-nc'
|
|
|
|
@options[:colors] = false
|
2011-09-01 13:38:53 +00:00
|
|
|
when '--cache'
|
|
|
|
@options[:enable_cache] = true
|
|
|
|
when '--no-cache'
|
|
|
|
@options[:enable_cache] = false
|
2011-06-16 13:51:49 +00:00
|
|
|
when '--keep'
|
|
|
|
@options[:remove_html_file] = false
|
|
|
|
when '--report'
|
2011-12-29 23:37:23 +00:00
|
|
|
warn REPORT_DEPRECATED_MESSAGE
|
|
|
|
|
2011-12-30 15:47:08 +00:00
|
|
|
add_reporter('File', arg)
|
|
|
|
add_reporter('Console')
|
2011-10-10 18:11:13 +00:00
|
|
|
when '--runner-out'
|
|
|
|
@options[:runner_output_filename] = arg
|
2011-06-16 13:51:49 +00:00
|
|
|
when '--jasmine-config', '-j'
|
|
|
|
@options[:jasmine_config] = arg
|
|
|
|
when '--no-full-run'
|
|
|
|
@options[:full_run] = false
|
2011-08-22 17:26:48 +00:00
|
|
|
when '--list', '-l'
|
|
|
|
@options[:do_list] = true
|
2012-01-11 13:44:28 +00:00
|
|
|
when '--quiet', '-q'
|
|
|
|
@options[:quiet] = true
|
2011-11-28 16:47:05 +00:00
|
|
|
when '--seed'
|
|
|
|
@options[:seed] = arg.to_i
|
2011-12-29 14:32:27 +00:00
|
|
|
when '--format', '-f'
|
|
|
|
add_reporter(arg)
|
|
|
|
when '--out'
|
2011-12-29 23:37:23 +00:00
|
|
|
add_reporter_file(arg)
|
2011-12-30 20:33:06 +00:00
|
|
|
when '-h', '--help'
|
|
|
|
print_help
|
|
|
|
|
|
|
|
exit
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_defaults_files
|
|
|
|
[ GLOBAL_DEFAULTS_FILE, DEFAULTS_FILE ].each do |file|
|
|
|
|
if File.file?(file)
|
|
|
|
File.readlines(file).collect { |line| line.strip.split(' ', 2) }.each { |*args| process_option(*args) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_command_line_args
|
|
|
|
command_line_args = GetoptLong.new(
|
|
|
|
[ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
|
|
|
|
[ '--no-colors', GetoptLong::NO_ARGUMENT ],
|
2011-09-01 13:38:53 +00:00
|
|
|
[ '--cache', GetoptLong::NO_ARGUMENT ],
|
2011-12-29 14:32:27 +00:00
|
|
|
[ '--no-cache', GetoptLong::NO_ARGUMENT ],
|
2011-06-16 13:51:49 +00:00
|
|
|
[ '--keep', GetoptLong::NO_ARGUMENT ],
|
2011-10-10 18:11:13 +00:00
|
|
|
[ '--runner-out', GetoptLong::REQUIRED_ARGUMENT ],
|
2011-06-16 13:51:49 +00:00
|
|
|
[ '--report', GetoptLong::REQUIRED_ARGUMENT ],
|
|
|
|
[ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ],
|
2011-08-22 17:26:48 +00:00
|
|
|
[ '--no-full-run', GetoptLong::NO_ARGUMENT ],
|
2011-11-28 16:47:05 +00:00
|
|
|
[ '--list', '-l', GetoptLong::NO_ARGUMENT ],
|
2011-12-29 14:32:27 +00:00
|
|
|
[ '--seed', GetoptLong::REQUIRED_ARGUMENT ],
|
|
|
|
[ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
|
2011-12-30 20:33:06 +00:00
|
|
|
[ '--out', GetoptLong::REQUIRED_ARGUMENT ],
|
2012-01-11 13:44:28 +00:00
|
|
|
[ '-h', '--help', GetoptLong::NO_ARGUMENT ],
|
|
|
|
[ '-q', '--quiet', GetoptLong::NO_ARGUMENT ]
|
2011-06-16 13:51:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
command_line_args.each { |*args| process_option(*args) }
|
|
|
|
end
|
2011-12-29 14:32:27 +00:00
|
|
|
|
|
|
|
def reporters
|
|
|
|
file_index = 0
|
|
|
|
|
|
|
|
@options[:reporters].collect do |reporter, file|
|
|
|
|
output = [ reporter ]
|
|
|
|
if file
|
|
|
|
output << "report:#{file_index}"
|
|
|
|
output << file
|
|
|
|
file_index += 1
|
|
|
|
else
|
|
|
|
output << "stdout"
|
|
|
|
end
|
|
|
|
|
|
|
|
output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-29 23:37:23 +00:00
|
|
|
def file_reporters
|
|
|
|
reporters.find_all { |reporter| reporter[1]["report:"] }
|
|
|
|
end
|
|
|
|
|
2011-12-29 14:32:27 +00:00
|
|
|
private
|
2011-12-29 23:37:23 +00:00
|
|
|
def add_reporter(name, file = nil)
|
2011-12-29 14:32:27 +00:00
|
|
|
if !@added_reporter
|
|
|
|
@options[:reporters] = []
|
|
|
|
@added_reporter = true
|
|
|
|
end
|
|
|
|
|
2011-12-29 23:37:23 +00:00
|
|
|
if (parts = name.split(':')).length == 2
|
|
|
|
name, file = parts
|
|
|
|
end
|
|
|
|
|
2011-12-29 14:32:27 +00:00
|
|
|
@options[:reporters] << [ name ]
|
2011-12-29 23:37:23 +00:00
|
|
|
|
|
|
|
add_reporter_file(file) if file
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_reporter_file(file)
|
|
|
|
@options[:reporters].last << file
|
2011-12-29 14:32:27 +00:00
|
|
|
end
|
2011-12-30 20:33:06 +00:00
|
|
|
|
|
|
|
def print_help
|
|
|
|
options = [
|
|
|
|
[ '-c, --colors', 'Enable colors (default: disabled)' ],
|
|
|
|
[ '-nc, --no-colors', 'Disable colors' ],
|
|
|
|
[ '--cache', 'Enable cache (default: enabled)' ],
|
|
|
|
[ '--no-cache', 'Disable cache' ],
|
|
|
|
[ '--keep', 'Keep runner files on failure' ],
|
|
|
|
[ '--runner-out <filename>', 'Write runner to specified filename' ],
|
|
|
|
[ '-j, --jasmine-config <config file>', 'Jasmine Yaml config to use' ],
|
|
|
|
[ '--no-full-run', 'Do not perform a full spec run after a successful targeted spec run' ],
|
|
|
|
[ '-l, --list', 'List files in the order they will be required' ],
|
|
|
|
[ '--seed', 'Random order seed for spec file ordering' ],
|
|
|
|
[ '-f, --format <reporter<:filename>>', 'Specify an output reporter and possibly output filename' ],
|
|
|
|
[ '--out <filename>', 'Specify output filename for last defined reporter' ],
|
2012-01-11 13:44:28 +00:00
|
|
|
[ '-q, --quiet', "Silence most non-test related warnings" ],
|
2011-12-30 20:33:06 +00:00
|
|
|
[ '-h, --help', "You're looking at it" ]
|
|
|
|
]
|
|
|
|
|
|
|
|
longest_length = options.collect(&:first).collect(&:length).max
|
|
|
|
|
|
|
|
puts <<-HELP
|
|
|
|
Usage: #{$0} [ options ] [ spec files ]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
#{options.collect { |option, description| " #{option.ljust(longest_length)} #{description}" }.join("\n")}
|
|
|
|
|
|
|
|
Available reporters:
|
|
|
|
Console Write out spec results to the console in a progress format (default)
|
2012-01-11 13:44:28 +00:00
|
|
|
Verbose Write out spec results to the console in a verbose format
|
2011-12-30 20:33:06 +00:00
|
|
|
File Write spec results in jasmine-headless-webkit ReportFile format
|
|
|
|
Tap Write spec results in TAP format
|
|
|
|
|
|
|
|
Add reporters to the jasmine.HeadlessReporter object to access them
|
|
|
|
(ex: jasmine.HeadlessReporter.Teamcity for the Teamcity reporter)
|
|
|
|
HELP
|
|
|
|
end
|
2011-06-16 13:51:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|