Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Runner into RuntimeConfig and a bunch of commands. Reorganized …
…application to use manual dependency injection.
- Loading branch information
Adam Pohorecki
committed
Jun 7, 2011
1 parent
f4d7581
commit 6d3cf50
Showing
19 changed files
with
500 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
require 'json' | ||
require 'fileutils' | ||
|
||
require File.expand_path(File.join('..', 'js_test_driver', 'config'), __FILE__) | ||
require File.expand_path(File.join('..', 'js_test_driver', 'runner'), __FILE__) | ||
require File.expand_path(File.join('..', 'js_test_driver', 'html_fixture'), __FILE__) | ||
require File.expand_path(File.join('..', 'js_test_driver', 'missing_dependency_error'), __FILE__) | ||
require File.expand_path(File.join('..', 'js_test_driver', 'commands', 'base_command'), __FILE__) | ||
require File.expand_path(File.join('..', 'js_test_driver', 'commands', 'jstd_jar_command'), __FILE__) | ||
require File.expand_path(File.join('..', 'js_test_driver', 'commands', 'capture_browsers_command'), __FILE__) | ||
require File.expand_path(File.join('..', 'js_test_driver', 'commands', 'generate_coverage_report'), __FILE__) | ||
module JsTestDriver | ||
autoload :Application, 'js_test_driver/application' | ||
autoload :Config, 'js_test_driver/config' | ||
autoload :HtmlFixture, 'js_test_driver/html_fixture' | ||
autoload :MissingDependencyError, 'js_test_driver/missing_dependency_error' | ||
autoload :Runner, 'js_test_driver/runner' | ||
autoload :RuntimeConfig, 'js_test_driver/runtime_config' | ||
autoload :VERSION, 'js_test_driver/version' | ||
|
||
module CLI | ||
autoload :CaptureBrowsers, 'js_test_driver/cli/capture_browsers' | ||
autoload :Run, 'js_test_driver/cli/run' | ||
autoload :RunTests, 'js_test_driver/cli/run_tests' | ||
autoload :StartServer, 'js_test_driver/cli/start_server' | ||
end | ||
|
||
module Commands | ||
autoload :BaseCommand, 'js_test_driver/commands/base_command' | ||
autoload :GenerateCoverageReport, 'js_test_driver/commands/generate_coverage_report' | ||
autoload :JstdJarCommand, 'js_test_driver/commands/jstd_jar_command' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module JsTestDriver | ||
|
||
class Application | ||
|
||
attr_reader :runtime_config | ||
|
||
def initialize(opts = {}) | ||
@runtime_config = JsTestDriver::RuntimeConfig.new(opts) | ||
end | ||
|
||
def config | ||
runtime_config.config | ||
end | ||
|
||
def start_server(opts = {}) | ||
JsTestDriver::CLI::StartServer.new(jstd_jar_command, runner).run(opts) | ||
end | ||
|
||
def capture_browsers(opts = {}) | ||
JsTestDriver::CLI::CaptureBrowsers.new(config, runner).run(opts) | ||
end | ||
|
||
def run_tests(opts = {}) | ||
JsTestDriver::CLI::RunTests.new(jstd_jar_command, runner).run(opts) | ||
end | ||
|
||
def run(opts = {}) | ||
JsTestDriver::CLI::Run.new(jstd_jar_command, runner, config, coverage_command).run(opts) | ||
end | ||
|
||
protected | ||
|
||
def runner | ||
JsTestDriver::Runner.new | ||
end | ||
|
||
def jstd_jar_command | ||
JsTestDriver::Commands::JstdJarCommand.new(runtime_config, config) | ||
end | ||
|
||
def coverage_command | ||
JsTestDriver::Commands::GenerateCoverageReport.new(runtime_config) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module JsTestDriver | ||
module CLI | ||
|
||
class CaptureBrowsers | ||
|
||
attr_reader :config, :runner | ||
|
||
def initialize(config, runner) | ||
@config = config | ||
@runner = runner | ||
end | ||
|
||
def run(opts = {}) | ||
browsers = opts[:browsers] || '' | ||
browsers = browsers.split(',') | ||
browsers = config.browsers if browsers.empty? | ||
|
||
url = config.server + "/capture?strict" | ||
|
||
browsers.each do |name| | ||
runner.runbg(browser_command(name, url)) | ||
end | ||
end | ||
|
||
protected | ||
|
||
def browser_command(name, url) | ||
JsTestDriver::Commands::BaseCommand.new(name).arg(url).to_s | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module JsTestDriver | ||
module CLI | ||
|
||
class Run | ||
|
||
attr_reader :command, :runner, :config, :coverage_command | ||
|
||
def initialize(jstd_jar_command, runner, config, coverage_command) | ||
@command = jstd_jar_command | ||
@runner = runner | ||
@config = config | ||
@coverage_command = coverage_command | ||
end | ||
|
||
def run(opts = {}) | ||
result = run_jstd_command(opts) | ||
generate_coverage_report(opts) | ||
return result | ||
end | ||
|
||
protected | ||
|
||
def run_jstd_command(opts) | ||
command | ||
.start_server | ||
.with_config | ||
.capture_browsers(opts[:browsers]) | ||
.run_tests(opts[:tests]) | ||
|
||
command.output_directory(opts[:output_xml_path]) if opts[:output_xml_path] | ||
command.capture_console if opts[:capture_console] | ||
command.verbose if opts[:verbose] | ||
|
||
return runner.run(command.to_s) | ||
end | ||
|
||
def generate_coverage_report(opts) | ||
return unless config.measure_coverage? && opts[:output_xml_path] | ||
|
||
if genhtml_installed? | ||
runner.run(coverage_command.output_path(opts[:output_xml_path]).to_s) | ||
else | ||
puts "Could not find genhtml. You must install lcov (sudo apt-get install lcov)" | ||
end | ||
end | ||
|
||
def genhtml_installed? | ||
!%x[which genhtml].strip.empty? | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module JsTestDriver | ||
module CLI | ||
|
||
class RunTests | ||
|
||
attr_reader :jstd_jar_command, :runner | ||
|
||
def initialize(jstd_jar_command, runner) | ||
@jstd_jar_command = jstd_jar_command | ||
@runner = runner | ||
end | ||
|
||
def run(opts = {}) | ||
jstd_jar_command.with_config.run_tests(opts[:tests]) | ||
|
||
runner.run(jstd_jar_command.to_s) | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module JsTestDriver | ||
module CLI | ||
|
||
class StartServer | ||
|
||
attr_reader :jstd_jar_command, :runner | ||
|
||
def initialize(jstd_jar_command, runner) | ||
@jstd_jar_command = jstd_jar_command | ||
@runner = runner | ||
end | ||
|
||
def run(opts = {}) | ||
runner.run(jstd_jar_command.start_server.to_s) | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.