js-test-server 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +31 -0
- data/Gemfile +17 -0
- data/README.markdown +9 -0
- data/Rakefile +63 -0
- data/bin/jasmine-server +9 -0
- data/bin/js-test-client +8 -0
- data/bin/js-test-server +9 -0
- data/bin/screw-unit-server +9 -0
- data/lib/js_test_server.rb +29 -0
- data/lib/js_test_server/client.rb +23 -0
- data/lib/js_test_server/client/runner.rb +129 -0
- data/lib/js_test_server/configuration.rb +69 -0
- data/lib/js_test_server/server.rb +14 -0
- data/lib/js_test_server/server/app.rb +10 -0
- data/lib/js_test_server/server/representations.rb +12 -0
- data/lib/js_test_server/server/representations/dir.html.rb +22 -0
- data/lib/js_test_server/server/representations/frameworks.rb +3 -0
- data/lib/js_test_server/server/representations/not_found.html.rb +13 -0
- data/lib/js_test_server/server/representations/page.html.rb +32 -0
- data/lib/js_test_server/server/representations/remote_control_subscriber.rb +17 -0
- data/lib/js_test_server/server/representations/suite.html.rb +54 -0
- data/lib/js_test_server/server/representations/suites.rb +6 -0
- data/lib/js_test_server/server/representations/suites/jasmine.html.rb +32 -0
- data/lib/js_test_server/server/representations/suites/screw_unit.html.rb +45 -0
- data/lib/js_test_server/server/resources.rb +14 -0
- data/lib/js_test_server/server/resources/file.rb +58 -0
- data/lib/js_test_server/server/resources/framework_file.rb +15 -0
- data/lib/js_test_server/server/resources/implementations_deprecation.rb +8 -0
- data/lib/js_test_server/server/resources/not_found.rb +25 -0
- data/lib/js_test_server/server/resources/remote_control.rb +80 -0
- data/lib/js_test_server/server/resources/resource.rb +12 -0
- data/lib/js_test_server/server/resources/spec_file.rb +47 -0
- data/lib/js_test_server/server/resources/web_root.rb +17 -0
- data/lib/js_test_server/server/runner.rb +62 -0
- data/scratch.rb +8 -0
- data/spec/frameworks/jasmine/cruise_config.rb +21 -0
- data/spec/frameworks/jasmine/spec/jasmine_helper.rb +44 -0
- data/spec/frameworks/jasmine/spec/jasmine_spec.rb +31 -0
- data/spec/functional/functional_spec_helper.rb +55 -0
- data/spec/functional/functional_spec_server_starter.rb +69 -0
- data/spec/functional/jasmine/jasmine_functional_spec.rb +27 -0
- data/spec/functional/screw-unit/screw_unit_functional_spec.rb +27 -0
- data/spec/functional_suite.rb +16 -0
- data/spec/spec_helpers/be_http.rb +32 -0
- data/spec/spec_helpers/example_group.rb +41 -0
- data/spec/spec_helpers/fake_deferrable.rb +3 -0
- data/spec/spec_helpers/fake_selenium_driver.rb +16 -0
- data/spec/spec_helpers/mock_session.rb +30 -0
- data/spec/spec_helpers/show_test_exceptions.rb +22 -0
- data/spec/spec_helpers/wait_for.rb +11 -0
- data/spec/spec_suite.rb +3 -0
- data/spec/unit/js_test_core/client/runner_spec.rb +198 -0
- data/spec/unit/js_test_core/configuration_spec.rb +44 -0
- data/spec/unit/js_test_core/resources/file_spec.rb +79 -0
- data/spec/unit/js_test_core/resources/framework_file_spec.rb +58 -0
- data/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +16 -0
- data/spec/unit/js_test_core/resources/not_found_spec.rb +49 -0
- data/spec/unit/js_test_core/resources/remote_control_spec.rb +117 -0
- data/spec/unit/js_test_core/resources/spec_file_spec.rb +147 -0
- data/spec/unit/js_test_core/resources/web_root_spec.rb +26 -0
- data/spec/unit/js_test_core/server/server_spec.rb +67 -0
- data/spec/unit/unit_spec_helper.rb +34 -0
- data/spec/unit_suite.rb +10 -0
- metadata +220 -0
data/CHANGES
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
- Added JsTestCore::Representations::Spec.project_js_files and .project_css_files
|
2
|
+
- Updated to erector 0.6.7, which fixes a bug related to including modules into Representations.
|
3
|
+
- Allow test suite to clear all cookies
|
4
|
+
- No longer using the /implementanions directory. Replace all cases of /implementations with /javascripts.
|
5
|
+
- Added support for custom suite files
|
6
|
+
- Added dependency on Erector
|
7
|
+
- Better error messages
|
8
|
+
- Changed dependency from Selenium to selenium-client
|
9
|
+
- Renamed Resources::Runner to Resources::SeleniumSession
|
10
|
+
- Changed /runners to /selenium_sessions
|
11
|
+
|
12
|
+
0.2.0
|
13
|
+
- Renamed Suite to Session to follow Selenium conventions
|
14
|
+
- Renamed SuiteFinish to SessionFinish to follow Selenium conventions
|
15
|
+
- Added /session, which uses the session_id cookie to derive the current session.
|
16
|
+
- Added /session/finished to be used to simplify client/server interactions.
|
17
|
+
- Remove File caching because it doesn't cause a noticable performance benefit over a local network and because it sometimes doesn't write over stale files.
|
18
|
+
- Client accepts selenium_browser_start_command parameter, which allows the user to parameterize the selenium_browser_start_command
|
19
|
+
- Added support for running specs in Internet Explorer via POST /runners/iexplore
|
20
|
+
- Resource file download performance improvements via caching and chunked sending
|
21
|
+
- Fixed false positive bug when Client connection times out
|
22
|
+
|
23
|
+
0.1.1
|
24
|
+
- SuiteFinish#post immediately closes the connection
|
25
|
+
|
26
|
+
0.1.0
|
27
|
+
- Initial Release extracted from JsTestCore.
|
28
|
+
- Added JsTestCore::WebRoot.dispatch_specs and .dispatch_strategy
|
29
|
+
- Extracted JsTestCore::Resources::Specs::SpecDir
|
30
|
+
- Extracted JsTestCore::Resources::Specs::SpecFile
|
31
|
+
- No longer depending on Guid. The child libraries are responsible for obtaining the Selenium session_id from the client by using top.runOptions.getSessionId().
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
group :gem do
|
2
|
+
gem 'sinatra', '1.0'
|
3
|
+
gem 'thin', '1.2.7'
|
4
|
+
gem 'erector', '0.7.2'
|
5
|
+
gem 'selenium-client', '1.2.18'
|
6
|
+
gem 'trollop', '1.16.2'
|
7
|
+
gem 'guid', '0.1.1'
|
8
|
+
gem 'json', '1.4.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem 'selenium-rc', '2.2.1'
|
13
|
+
gem 'lsof', '0.3.0'
|
14
|
+
gem 'rack-test', '0.5.3'
|
15
|
+
gem 'rr', '0.10.11'
|
16
|
+
gem 'nokogiri', '1.4.1'
|
17
|
+
end
|
data/README.markdown
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
= JsTestServer
|
2
|
+
JsTestServer provides a command line runner and html suite file generation for your favorite Javascript testing framework.
|
3
|
+
|
4
|
+
== Current supported frameworks
|
5
|
+
* Jasmine
|
6
|
+
* Screw Unit
|
7
|
+
|
8
|
+
== Thanks To
|
9
|
+
* Aman Gupta for advice and patch to the Remote Control
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "rake"
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/contrib/rubyforgepublisher'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
require 'bundler'
|
8
|
+
|
9
|
+
desc "Runs the Rspec suite"
|
10
|
+
task(:default) do
|
11
|
+
run_suite
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Runs the Rspec suite"
|
15
|
+
task(:spec) do
|
16
|
+
run_suite
|
17
|
+
end
|
18
|
+
|
19
|
+
def run_suite
|
20
|
+
dir = File.dirname(__FILE__)
|
21
|
+
system("ruby #{dir}/spec/spec_suite.rb") || raise("Example Suite failed")
|
22
|
+
end
|
23
|
+
|
24
|
+
PKG_NAME = "js-test-server"
|
25
|
+
PKG_VERSION = "0.2.0"
|
26
|
+
PKG_FILES = FileList[
|
27
|
+
'[A-Z]*',
|
28
|
+
'*.rb',
|
29
|
+
'lib/**/*.rb',
|
30
|
+
'core/**',
|
31
|
+
'bin/**',
|
32
|
+
'spec/**/*.rb'
|
33
|
+
]
|
34
|
+
|
35
|
+
spec = Gem::Specification.new do |s|
|
36
|
+
s.name = PKG_NAME
|
37
|
+
s.version = PKG_VERSION
|
38
|
+
s.summary = "The JsTestServer library is the core javascript test server library used by several JS Test server libraries."
|
39
|
+
s.test_files = "spec/spec_suite.rb"
|
40
|
+
s.description = s.summary
|
41
|
+
|
42
|
+
s.files = PKG_FILES.to_a
|
43
|
+
s.require_path = 'lib'
|
44
|
+
|
45
|
+
s.has_rdoc = true
|
46
|
+
|
47
|
+
s.test_files = Dir.glob('spec/*_spec.rb')
|
48
|
+
s.require_path = 'lib'
|
49
|
+
s.author = "Brian Takita"
|
50
|
+
s.email = "brian.takita@gmail.com"
|
51
|
+
s.homepage = "http://pivotallabs.com"
|
52
|
+
s.rubyforge_project = "pivotalrb"
|
53
|
+
Bundler::Definition.from_gemfile("#{File.dirname(__FILE__)}/Gemfile").dependencies.select do |dependency|
|
54
|
+
dependency.groups.include?(:gem)
|
55
|
+
end.each do |dependency|
|
56
|
+
s.add_dependency(dependency.name, dependency.version_requirements)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
61
|
+
pkg.need_zip = true
|
62
|
+
pkg.need_tar = true
|
63
|
+
end
|
data/bin/jasmine-server
ADDED
data/bin/js-test-client
ADDED
data/bin/js-test-server
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#bin/js-test-server --spec-path=./js-test-server/spec/functional/jasmine/example_spec --root-path=./js-test-server/spec/example_root --framework-name=jasmine --framework-path=./js-test-server/spec/frameworks/jasmine/lib
|
3
|
+
|
4
|
+
dir = File.dirname(__FILE__)
|
5
|
+
$LOAD_PATH.unshift("#{dir}/../lib")
|
6
|
+
|
7
|
+
require "rubygems"
|
8
|
+
require "js_test_server"
|
9
|
+
JsTestServer::Server::Runner.new.cli(*ARGV)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path("#{dir}/../vendor/lucky-luciano/lib")
|
3
|
+
require "lucky_luciano"
|
4
|
+
|
5
|
+
require "timeout"
|
6
|
+
require "selenium/client"
|
7
|
+
require "trollop"
|
8
|
+
require "json"
|
9
|
+
require "erector"
|
10
|
+
|
11
|
+
Erector::Widget.prettyprint_default = true
|
12
|
+
|
13
|
+
require "#{dir}/js_test_server/configuration"
|
14
|
+
require "#{dir}/js_test_server/server"
|
15
|
+
require "#{dir}/js_test_server/client"
|
16
|
+
|
17
|
+
module JsTestServer
|
18
|
+
class << self
|
19
|
+
Configuration.instance = Configuration.new
|
20
|
+
|
21
|
+
def method_missing(method_name, *args, &block)
|
22
|
+
if Configuration.instance.respond_to?(method_name)
|
23
|
+
Configuration.instance.send(method_name, *args, &block)
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module JsTestServer
|
2
|
+
module Client
|
3
|
+
RUNNING_RUNNER_STATE = "running"
|
4
|
+
PASSED_RUNNER_STATE = "passed"
|
5
|
+
FAILED_RUNNER_STATE = "failed"
|
6
|
+
FINISHED_RUNNER_STATES = [PASSED_RUNNER_STATE, FAILED_RUNNER_STATE]
|
7
|
+
|
8
|
+
DEFAULT_SELENIUM_BROWSER = "*firefox"
|
9
|
+
DEFAULT_SELENIUM_HOST = "0.0.0.0"
|
10
|
+
DEFAULT_SELENIUM_PORT = 4444
|
11
|
+
DEFAULT_SPEC_URL = "http://localhost:8080/specs"
|
12
|
+
DEFAULT_TIMEOUT = 60
|
13
|
+
|
14
|
+
class ClientException < Exception
|
15
|
+
end
|
16
|
+
|
17
|
+
class InvalidStatusResponse < ClientException
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
dir = File.dirname(__FILE__)
|
23
|
+
require "#{dir}/client/runner"
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module JsTestServer
|
2
|
+
module Client
|
3
|
+
class Runner
|
4
|
+
class << self
|
5
|
+
def run(parameters={})
|
6
|
+
new(parameters).run
|
7
|
+
end
|
8
|
+
|
9
|
+
def run_argv(argv)
|
10
|
+
opts = Trollop.options(argv) do
|
11
|
+
opt(
|
12
|
+
:selenium_browser,
|
13
|
+
"The Selenium browser (e.g. *firefox). See http://selenium-rc.openqa.org/",
|
14
|
+
:type => String,
|
15
|
+
:default => DEFAULT_SELENIUM_BROWSER
|
16
|
+
)
|
17
|
+
opt(
|
18
|
+
:selenium_host,
|
19
|
+
"The host name of the Selenium Server relative to where this file is executed",
|
20
|
+
:type => String,
|
21
|
+
:default => DEFAULT_SELENIUM_HOST
|
22
|
+
)
|
23
|
+
opt(
|
24
|
+
:selenium_port,
|
25
|
+
"The port of the Selenium Server relative to where this file is executed",
|
26
|
+
:type => Integer,
|
27
|
+
:default => DEFAULT_SELENIUM_PORT
|
28
|
+
)
|
29
|
+
opt(
|
30
|
+
:spec_url,
|
31
|
+
"The url of the js spec server, relative to the browsers running via the Selenium Server",
|
32
|
+
:type => String,
|
33
|
+
:default => DEFAULT_SPEC_URL
|
34
|
+
)
|
35
|
+
opt(
|
36
|
+
:timeout,
|
37
|
+
"The timeout limit of the test run",
|
38
|
+
:type => Integer,
|
39
|
+
:default => DEFAULT_TIMEOUT
|
40
|
+
)
|
41
|
+
end
|
42
|
+
run opts
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_reader :parameters, :selenium_client, :current_status, :flushed_console
|
47
|
+
|
48
|
+
def initialize(parameters)
|
49
|
+
@parameters = parameters
|
50
|
+
@flushed_console = ""
|
51
|
+
end
|
52
|
+
|
53
|
+
def run
|
54
|
+
if parameters[:timeout]
|
55
|
+
Timeout.timeout(parameters[:timeout]) {do_run}
|
56
|
+
else
|
57
|
+
do_run
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
def do_run
|
63
|
+
start_selenium_client
|
64
|
+
wait_for_session_to_finish
|
65
|
+
flush_console
|
66
|
+
suite_passed?
|
67
|
+
end
|
68
|
+
|
69
|
+
def start_selenium_client
|
70
|
+
uri = URI.parse(parameters[:spec_url] || DEFAULT_SPEC_URL)
|
71
|
+
@selenium_client = Selenium::Client::Driver.new(
|
72
|
+
:host => parameters[:selenium_host] || DEFAULT_SELENIUM_HOST,
|
73
|
+
:port => parameters[:selenium_port] || DEFAULT_SELENIUM_PORT,
|
74
|
+
:browser => parameters[:selenium_browser] || DEFAULT_SELENIUM_BROWSER,
|
75
|
+
:url => "#{uri.scheme}://#{uri.host}:#{uri.port}"
|
76
|
+
)
|
77
|
+
selenium_client.start
|
78
|
+
selenium_client.open([uri.path, uri.query].compact.join("?"))
|
79
|
+
|
80
|
+
at_exit do
|
81
|
+
selenium_client.stop
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def wait_for_session_to_finish
|
86
|
+
while !suite_finished?
|
87
|
+
poll
|
88
|
+
flush_console
|
89
|
+
sleep 0.1
|
90
|
+
end
|
91
|
+
if suite_passed?
|
92
|
+
STDOUT.puts(PASSED_RUNNER_STATE.capitalize)
|
93
|
+
else
|
94
|
+
STDOUT.puts(FAILED_RUNNER_STATE.capitalize)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def poll
|
99
|
+
raw_status = selenium_client.get_eval("window.JsTestServer.status()")
|
100
|
+
unless raw_status.to_s == ""
|
101
|
+
@current_status = JSON.parse(raw_status)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def suite_finished?
|
106
|
+
current_status && FINISHED_RUNNER_STATES.include?(runner_state)
|
107
|
+
end
|
108
|
+
|
109
|
+
def flush_console
|
110
|
+
if current_status && console != ""
|
111
|
+
STDOUT.print(console.gsub(flushed_console, ""))
|
112
|
+
@flushed_console = console
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def suite_passed?
|
117
|
+
runner_state == PASSED_RUNNER_STATE
|
118
|
+
end
|
119
|
+
|
120
|
+
def runner_state
|
121
|
+
current_status["runner_state"]
|
122
|
+
end
|
123
|
+
|
124
|
+
def console
|
125
|
+
current_status["console"] || ""
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module JsTestServer
|
2
|
+
class Configuration
|
3
|
+
class << self
|
4
|
+
attr_accessor :instance
|
5
|
+
|
6
|
+
def method_missing(method_name, *args, &block)
|
7
|
+
if Configuration.instance.respond_to?(method_name)
|
8
|
+
Configuration.instance.send(method_name, *args, &block)
|
9
|
+
else
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :host, :port, :spec_path, :root_path, :framework_path, :framework_name
|
16
|
+
attr_writer :host, :port, :framework_path, :framework_name
|
17
|
+
|
18
|
+
def initialize(params={})
|
19
|
+
params = Server::DEFAULTS.dup.merge(params)
|
20
|
+
@spec_path = ::File.expand_path(params[:spec_path])
|
21
|
+
@root_path = ::File.expand_path(params[:root_path])
|
22
|
+
@host = params[:host]
|
23
|
+
@port = params[:port]
|
24
|
+
@framework_path = params[:framework_path]
|
25
|
+
@framework_name = params[:framework_name]
|
26
|
+
end
|
27
|
+
|
28
|
+
def suite_representation_class
|
29
|
+
if framework_name
|
30
|
+
JsTestServer::Server::Representations::Suites.const_get(framework_name.gsub("-", "_").camelcase)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def spec_path=(path)
|
35
|
+
validate_path(path)
|
36
|
+
@spec_path = path
|
37
|
+
end
|
38
|
+
|
39
|
+
def root_path=(path)
|
40
|
+
validate_path(path)
|
41
|
+
@root_path = path
|
42
|
+
end
|
43
|
+
|
44
|
+
def js_test_server_root_path
|
45
|
+
"#{library_root_dir}/public"
|
46
|
+
end
|
47
|
+
|
48
|
+
def root_url
|
49
|
+
"http://#{host}:#{port}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def rackup_path
|
53
|
+
File.expand_path("#{File.dirname(__FILE__)}/server/standalone.ru")
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def library_root_dir
|
59
|
+
dir = File.dirname(__FILE__)
|
60
|
+
File.expand_path("#{dir}/../..")
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate_path(path)
|
64
|
+
unless File.directory?(path)
|
65
|
+
raise ArgumentError, "#{path} must be a directory"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module JsTestServer::Server
|
2
|
+
DEFAULTS = {
|
3
|
+
:host => "0.0.0.0",
|
4
|
+
:port => 8080,
|
5
|
+
:spec_path => File.expand_path("./spec/javascripts"),
|
6
|
+
:root_path => File.expand_path("./public"),
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
dir = File.dirname(__FILE__)
|
11
|
+
require "#{dir}/server/runner"
|
12
|
+
require "#{dir}/server/resources"
|
13
|
+
require "#{dir}/server/representations"
|
14
|
+
require "#{dir}/server/app"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class JsTestServer::Server::App < Sinatra::Base
|
2
|
+
set :logging, true
|
3
|
+
register(JsTestServer::Server::Resources::WebRoot.route_handler)
|
4
|
+
register(JsTestServer::Server::Resources::SpecFile.route_handler)
|
5
|
+
register(JsTestServer::Server::Resources::File.route_handler)
|
6
|
+
register(JsTestServer::Server::Resources::FrameworkFile.route_handler)
|
7
|
+
register(JsTestServer::Server::Resources::RemoteControl.route_handler)
|
8
|
+
register(JsTestServer::Server::Resources::ImplementationsDeprecation.route_handler)
|
9
|
+
register(JsTestServer::Server::Resources::NotFound.route_handler)
|
10
|
+
end
|