Class: JsTestDriver::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/js_test_driver/runner.rb

Overview

The Runner class is used

Defined Under Namespace

Classes: Command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Runner

Returns a new instance of Runner.



5
6
7
# File 'lib/js_test_driver/runner.rb', line 5

def initialize(attributes = {})
  self.attributes = attributes
end

Instance Attribute Details

#configObject



12
13
14
# File 'lib/js_test_driver/runner.rb', line 12

def config
  @config ||= parse_config
end

#config_pathObject



28
29
30
# File 'lib/js_test_driver/runner.rb', line 28

def config_path
  @config_path ||= default_config_path
end

#generated_files_dirObject

this is where the generated files will be saved, by default this is ‘pwd`/.js_test_driver

the generated files are the config yml file and the fixture files



21
22
23
# File 'lib/js_test_driver/runner.rb', line 21

def generated_files_dir
  @generated_files_dir || default_generated_files_dir
end

#jar_pathObject



35
36
37
# File 'lib/js_test_driver/runner.rb', line 35

def jar_path
  @jar_path ||= default_jar_path
end

#tmp_path=(value) ⇒ Object (writeonly)

this is where the config yml file will be saved, by default its saved in the generated files directory under the name jsTestDriver.conf



41
42
43
# File 'lib/js_test_driver/runner.rb', line 41

def tmp_path=(value)
  @tmp_path = value
end

Instance Method Details

#add_capture_browsers(command, browsers) ⇒ Object

Raises:

  • (ArgumentError)


113
114
115
116
117
# File 'lib/js_test_driver/runner.rb', line 113

def add_capture_browsers(command, browsers)
  browsers ||= config.browsers.join(',')
  raise ArgumentError.new("No browsers defined!") if browsers == ""
  command.option('--browser', browsers)
end

#add_capture_console(command) ⇒ Object



125
126
127
# File 'lib/js_test_driver/runner.rb', line 125

def add_capture_console(command)
  command.option('--captureConsole')
end

#add_output_directory(command, path) ⇒ Object



119
120
121
122
123
# File 'lib/js_test_driver/runner.rb', line 119

def add_output_directory(command, path)
  path = File.expand_path(path)
  FileUtils.mkdir_p(path) unless File.exists?(path)
  command.option('--testOutput', path)
end

#add_run_tests(command, tests) ⇒ Object



109
110
111
# File 'lib/js_test_driver/runner.rb', line 109

def add_run_tests(command, tests)
  command.option('--tests', tests || "all")
end

#add_start_server(command) ⇒ Object



105
106
107
# File 'lib/js_test_driver/runner.rb', line 105

def add_start_server(command)
  command.option('--port', config.port)
end

#add_with_config(command) ⇒ Object



129
130
131
132
# File 'lib/js_test_driver/runner.rb', line 129

def add_with_config(command)
  save_config_file(config_yml_path)
  command.option('--config', config_yml_path)
end

#capture_browsers(browsers = nil) ⇒ Object

captures the browsers

by default it will capture the browsers specified in the config, but you can pass an argument like ‘opera,chrome,firefox’ to capture opera, chrome and firefox



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/js_test_driver/runner.rb', line 60

def capture_browsers(browsers = nil)
  browsers ||= ''
  browsers = browsers.split(',')
  browsers = config.browsers if browsers.empty?

  url = config.server + "/capture"

  browsers.each do |browser|
    spawn("#{browser} \'#{url}\'")
  end
end

#config_yml_pathObject



43
44
45
# File 'lib/js_test_driver/runner.rb', line 43

def config_yml_path
  @tmp_path ||= default_config_yml_path
end

#execute_jarObject



134
135
136
# File 'lib/js_test_driver/runner.rb', line 134

def execute_jar
  Command.new('java').option('-jar', jar_path)
end

#generate_html_coverage_report(output_path) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/js_test_driver/runner.rb', line 138

def generate_html_coverage_report(output_path)
  unless genhtml_installed?
    puts "Could not find genhtml. You must install lcov (sudo apt-get install lcov)"
    return
  end

  output_path = File.expand_path(output_path)

  config_file_name = File.basename(config_yml_path)
  coverage_file_name = config_file_name + '-coverage.dat'
  coverage_file_path = File.join(output_path, coverage_file_name)
  coverage_out_dir = File.join(output_path, 'coverage')

  system("genhtml -o #{coverage_out_dir} #{coverage_file_path}")
end

#run_tests(tests = nil) ⇒ Object

runs the tests specified by the argument

by default it will run all the tests, but you can pass a string like: ‘TestCase’ or ‘TestCase.test’ to run either a single test case or a single test



77
78
79
80
81
82
83
84
# File 'lib/js_test_driver/runner.rb', line 77

def run_tests(tests = nil)
  command = execute_jar

  add_with_config(command)
  add_run_tests(command, tests)

  command.run
end

#start_serverObject

starts the server on the default port specified in the config file



48
49
50
51
52
53
54
# File 'lib/js_test_driver/runner.rb', line 48

def start_server
  command = execute_jar

  add_start_server(command)

  command.run
end

#start_server_capture_and_run(tests = nil, browsers = nil, output_xml_path = nil, console = nil) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/js_test_driver/runner.rb', line 86

def start_server_capture_and_run(tests = nil, browsers = nil, output_xml_path = nil, console = nil)
  command = execute_jar

  add_start_server(command)
  add_with_config(command)
  add_capture_browsers(command, browsers)
  add_run_tests(command, tests)
  add_output_directory(command, output_xml_path) if output_xml_path
  add_capture_console(command) if console

  result = command.run

  if config.measure_coverage? && output_xml_path
    generate_html_coverage_report(output_xml_path)
  end

  return result
end