honkster-js-test-server 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/CHANGES +40 -0
  2. data/Gemfile +21 -0
  3. data/Gemfile.lock +60 -0
  4. data/README.markdown +9 -0
  5. data/Rakefile +67 -0
  6. data/bin/jasmine-server +9 -0
  7. data/bin/js-test-client +8 -0
  8. data/bin/js-test-server +9 -0
  9. data/bin/screw-unit-server +9 -0
  10. data/lib/js_test_server.rb +29 -0
  11. data/lib/js_test_server/client.rb +23 -0
  12. data/lib/js_test_server/client/runner.rb +130 -0
  13. data/lib/js_test_server/configuration.rb +69 -0
  14. data/lib/js_test_server/server.rb +14 -0
  15. data/lib/js_test_server/server/app.rb +10 -0
  16. data/lib/js_test_server/server/resources.rb +14 -0
  17. data/lib/js_test_server/server/resources/file.rb +58 -0
  18. data/lib/js_test_server/server/resources/framework_file.rb +15 -0
  19. data/lib/js_test_server/server/resources/implementations_deprecation.rb +8 -0
  20. data/lib/js_test_server/server/resources/not_found.rb +25 -0
  21. data/lib/js_test_server/server/resources/remote_control.rb +80 -0
  22. data/lib/js_test_server/server/resources/resource.rb +12 -0
  23. data/lib/js_test_server/server/resources/spec_file.rb +47 -0
  24. data/lib/js_test_server/server/resources/web_root.rb +17 -0
  25. data/lib/js_test_server/server/runner.rb +77 -0
  26. data/lib/js_test_server/server/standalone.ru +1 -0
  27. data/lib/js_test_server/server/views.rb +12 -0
  28. data/lib/js_test_server/server/views/dir.html.rb +22 -0
  29. data/lib/js_test_server/server/views/frameworks.rb +3 -0
  30. data/lib/js_test_server/server/views/not_found.html.rb +13 -0
  31. data/lib/js_test_server/server/views/page.html.rb +40 -0
  32. data/lib/js_test_server/server/views/remote_control_subscriber.rb +17 -0
  33. data/lib/js_test_server/server/views/suite.html.rb +54 -0
  34. data/lib/js_test_server/server/views/suites.rb +6 -0
  35. data/lib/js_test_server/server/views/suites/jasmine.html.rb +30 -0
  36. data/lib/js_test_server/server/views/suites/screw_unit.html.rb +44 -0
  37. data/public/js_test_server.js +565 -0
  38. data/public/js_test_server/jasmine_driver.js +63 -0
  39. data/public/js_test_server/remote_control.js +28 -0
  40. data/public/js_test_server/screw_unit_driver.js +31 -0
  41. data/scratch.rb +8 -0
  42. data/spec/frameworks/jasmine/cruise_config.rb +21 -0
  43. data/spec/frameworks/jasmine/spec/jasmine_helper.rb +44 -0
  44. data/spec/frameworks/jasmine/spec/jasmine_spec.rb +31 -0
  45. data/spec/functional/functional_spec_helper.rb +55 -0
  46. data/spec/functional/functional_spec_server_starter.rb +69 -0
  47. data/spec/functional/jasmine/jasmine_functional_spec.rb +27 -0
  48. data/spec/functional/screw-unit/screw_unit_functional_spec.rb +27 -0
  49. data/spec/functional_suite.rb +16 -0
  50. data/spec/spec_helpers/be_http.rb +32 -0
  51. data/spec/spec_helpers/example_group.rb +41 -0
  52. data/spec/spec_helpers/fake_deferrable.rb +3 -0
  53. data/spec/spec_helpers/fake_selenium_driver.rb +16 -0
  54. data/spec/spec_helpers/mock_session.rb +30 -0
  55. data/spec/spec_helpers/show_test_exceptions.rb +22 -0
  56. data/spec/spec_helpers/wait_for.rb +11 -0
  57. data/spec/spec_suite.rb +3 -0
  58. data/spec/unit/js_test_core/client/runner_spec.rb +198 -0
  59. data/spec/unit/js_test_core/configuration_spec.rb +44 -0
  60. data/spec/unit/js_test_core/resources/file_spec.rb +79 -0
  61. data/spec/unit/js_test_core/resources/framework_file_spec.rb +58 -0
  62. data/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +16 -0
  63. data/spec/unit/js_test_core/resources/not_found_spec.rb +49 -0
  64. data/spec/unit/js_test_core/resources/remote_control_spec.rb +117 -0
  65. data/spec/unit/js_test_core/resources/spec_file_spec.rb +147 -0
  66. data/spec/unit/js_test_core/resources/web_root_spec.rb +26 -0
  67. data/spec/unit/js_test_core/server/server_spec.rb +103 -0
  68. data/spec/unit/unit_spec_helper.rb +34 -0
  69. data/spec/unit_suite.rb +10 -0
  70. data/vendor/lucky-luciano/lib/lucky_luciano.rb +5 -0
  71. data/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +142 -0
  72. data/vendor/lucky-luciano/lib/lucky_luciano/resource/path.rb +24 -0
  73. data/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  74. data/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  75. data/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +276 -0
  76. data/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  77. data/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
  78. metadata +146 -0
data/CHANGES ADDED
@@ -0,0 +1,40 @@
1
+ 0.2.7
2
+ - Fixed issue where Jasmine Runner hangs when there is no window.console
3
+ - Fixed selenium runner for Jasmine.
4
+
5
+ 0.2.6
6
+ - All js files are loaded, instead of *_spec.js.
7
+
8
+ 0.2.5
9
+ - Renamed JsTestServer::Representations to JsTestServer::Views
10
+ - Added JsTestServer::Views::Spec.project_js_files and .project_css_files
11
+ - Updated to erector 0.6.7, which fixes a bug related to including modules into Views.
12
+ - Allow test suite to clear all cookies
13
+ - No longer using the /implementanions directory. Replace all cases of /implementations with /javascripts.
14
+ - Added support for custom suite files
15
+ - Added dependency on Erector
16
+ - Better error messages
17
+ - Changed dependency from Selenium to selenium-client
18
+ - Renamed Resources::Runner to Resources::SeleniumSession
19
+ - Changed /runners to /selenium_sessions
20
+
21
+ 0.2.0
22
+ - Renamed Suite to Session to follow Selenium conventions
23
+ - Renamed SuiteFinish to SessionFinish to follow Selenium conventions
24
+ - Added /session, which uses the session_id cookie to derive the current session.
25
+ - Added /session/finished to be used to simplify client/server interactions.
26
+ - 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.
27
+ - Client accepts selenium_browser_start_command parameter, which allows the user to parameterize the selenium_browser_start_command
28
+ - Added support for running specs in Internet Explorer via POST /runners/iexplore
29
+ - Resource file download performance improvements via caching and chunked sending
30
+ - Fixed false positive bug when Client connection times out
31
+
32
+ 0.1.1
33
+ - SuiteFinish#post immediately closes the connection
34
+
35
+ 0.1.0
36
+ - Initial Release extracted from JsTestCore.
37
+ - Added JsTestCore::WebRoot.dispatch_specs and .dispatch_strategy
38
+ - Extracted JsTestCore::Resources::Specs::SpecDir
39
+ - Extracted JsTestCore::Resources::Specs::SpecFile
40
+ - 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,21 @@
1
+ source :gemcutter
2
+ group :gem do
3
+ gem 'sinatra', '>=1.0'
4
+ gem 'thin', '>=1.2.7'
5
+ gem 'erector', '0.7.2'
6
+ gem 'selenium-client', '1.2.18'
7
+ gem 'trollop', '>=1.16.2'
8
+ gem 'guid', '>=0.1.1'
9
+ gem 'json', '>=1.4.0'
10
+ gem 'activesupport'
11
+ gem 'i18n'
12
+ end
13
+
14
+ group :test do
15
+ gem 'rspec', '1.3.1'
16
+ gem 'selenium-rc', '2.2.1'
17
+ gem 'lsof', '0.3.0'
18
+ gem 'rack-test', '0.5.3'
19
+ gem 'rr', '0.10.11'
20
+ gem 'nokogiri', '1.4.1'
21
+ end
@@ -0,0 +1,60 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (2.3.10)
5
+ daemons (1.1.0)
6
+ erector (0.7.2)
7
+ hoe (>= 1.5.0)
8
+ eventmachine (0.12.10)
9
+ guid (0.1.1)
10
+ hoe (2.7.0)
11
+ rake (>= 0.8.7)
12
+ rubyforge (>= 2.0.4)
13
+ i18n (0.5.0)
14
+ json (1.4.6)
15
+ json_pure (1.4.6)
16
+ lsof (0.3.0)
17
+ nokogiri (1.4.1)
18
+ rack (1.2.1)
19
+ rack-test (0.5.3)
20
+ rack (>= 1.0)
21
+ rake (0.8.7)
22
+ rr (0.10.11)
23
+ rspec (1.3.1)
24
+ rubyforge (2.0.4)
25
+ json_pure (>= 1.1.7)
26
+ selenium-client (1.2.18)
27
+ selenium-rc (2.2.1)
28
+ selenium-client (>= 1.2.18)
29
+ sinatra (1.1.0)
30
+ rack (~> 1.1)
31
+ tilt (~> 1.1)
32
+ thin (1.2.7)
33
+ daemons (>= 1.0.9)
34
+ eventmachine (>= 0.12.6)
35
+ rack (>= 1.0.0)
36
+ tilt (1.1)
37
+ trollop (1.16.2)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ activesupport
44
+ erector (= 0.7.2)
45
+ guid (>= 0.1.1)
46
+ i18n
47
+ json (>= 1.4.0)
48
+ lsof (= 0.3.0)
49
+ nokogiri (= 1.4.1)
50
+ rack-test (= 0.5.3)
51
+ rr (= 0.10.11)
52
+ rspec (= 1.3.1)
53
+ selenium-client (= 1.2.18)
54
+ selenium-rc (= 2.2.1)
55
+ sinatra (>= 1.0)
56
+ thin (>= 1.2.7)
57
+ trollop (>= 1.16.2)
58
+
59
+ METADATA
60
+ version: 1.0.6
@@ -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
@@ -0,0 +1,67 @@
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
+ desc "Tag the release and push"
20
+ task :release do
21
+ tag_name = "v#{PKG_VERSION}"
22
+ system("git tag #{tag_name} && git push origin #{tag_name}")
23
+ end
24
+
25
+ def run_suite
26
+ dir = File.dirname(__FILE__)
27
+ system("ruby #{dir}/spec/spec_suite.rb") || raise("Example Suite failed")
28
+ end
29
+
30
+ PKG_NAME = "honkster-js-test-server"
31
+ PKG_VERSION = "0.2.9"
32
+ PKG_FILES = FileList[
33
+ '[A-Z]*',
34
+ '*.rb',
35
+ 'lib/**/**',
36
+ 'bin/**/**',
37
+ 'public/**/**',
38
+ 'spec/**/*.rb',
39
+ 'vendor/**/*.rb'
40
+ ]
41
+
42
+ spec = Gem::Specification.new do |s|
43
+ s.name = PKG_NAME
44
+ s.version = PKG_VERSION
45
+ s.summary = "The JsTestServer library is the core javascript test server library used by several JS Test server libraries."
46
+ s.test_files = "spec/spec_suite.rb"
47
+ s.description = s.summary
48
+
49
+ s.files = PKG_FILES.to_a
50
+ s.require_path = 'lib'
51
+
52
+ s.has_rdoc = true
53
+
54
+ s.test_files = Dir.glob('spec/*_spec.rb')
55
+ s.executables = Dir.glob('bin/*').map do |file|
56
+ File.basename(file)
57
+ end
58
+ s.require_path = 'lib'
59
+ s.author = "Brian Takita"
60
+ s.email = "brian.takita@gmail.com"
61
+ s.homepage = "http://github.com/honkster/js-test-server"
62
+ end
63
+
64
+ Rake::GemPackageTask.new(spec) do |pkg|
65
+ pkg.need_zip = true
66
+ pkg.need_tar = true
67
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift("#{dir}/../lib")
5
+
6
+ require "rubygems"
7
+ require "js_test_server"
8
+ JsTestServer::Server::DEFAULTS[:framework_name] = "jasmine"
9
+ JsTestServer::Server::Runner.new.cli(*ARGV)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift("#{dir}/../lib")
5
+
6
+ require "rubygems"
7
+ require "js_test_server"
8
+ JsTestServer::Client::Runner.run_argv(ARGV)
@@ -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,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift("#{dir}/../lib")
5
+
6
+ require "rubygems"
7
+ require "js_test_server"
8
+ JsTestServer::Server::DEFAULTS[:framework_name] = "screw-unit"
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,130 @@
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 ? window.JsTestServer.status() : ''")
100
+ unless raw_status.to_s == ""
101
+ @current_status = JSON.parse(raw_status)
102
+ # puts "#{__FILE__}:#{__LINE__} #{console.inspect}"
103
+ end
104
+ end
105
+
106
+ def suite_finished?
107
+ current_status && FINISHED_RUNNER_STATES.include?(runner_state)
108
+ end
109
+
110
+ def flush_console
111
+ if current_status && console != ""
112
+ STDOUT.print(console.gsub(flushed_console, ""))
113
+ @flushed_console = console
114
+ end
115
+ end
116
+
117
+ def suite_passed?
118
+ runner_state == PASSED_RUNNER_STATE
119
+ end
120
+
121
+ def runner_state
122
+ current_status["runner_state"]
123
+ end
124
+
125
+ def console
126
+ current_status["console"] || ""
127
+ end
128
+ end
129
+ end
130
+ 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_view_class
29
+ if framework_name
30
+ JsTestServer::Server::Views::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