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
@@ -0,0 +1,63 @@
1
+ JsTestServer.JasmineDriver = {};
2
+
3
+ JsTestServer.JasmineDriver.init = function() {
4
+ JsTestServer.JasmineDriver.instance = new JsTestServer.JasmineDriver.Instance();
5
+ JsTestServer.JasmineDriver.instance.init();
6
+ JsTestServer.JasmineDriver.instance.startJasmine();
7
+ };
8
+
9
+ JsTestServer.JasmineDriver.Instance = function() {
10
+ };
11
+
12
+ (function(Instance) {
13
+ var jsTestServerReporter;
14
+
15
+ Instance.prototype.init = function() {
16
+ this.defineStatusMethod();
17
+ };
18
+
19
+ Instance.prototype.defineStatusMethod = function() {
20
+ JsTestServer.status = function() {
21
+ var runnerState;
22
+ var jasmineEnv = jasmine.getEnv();
23
+ jasmineEnv.reporter.log("jsTestServerReporter.finished: " + jsTestServerReporter.finished)
24
+
25
+ return JsTestServer.JSON.stringify({
26
+ "runner_state": jsTestServerReporter.runnerState,
27
+ "console": jsTestServerReporter.console
28
+ });
29
+ };
30
+ };
31
+
32
+ Instance.prototype.startJasmine = function() {
33
+ var jasmineEnv = jasmine.getEnv();
34
+ jsTestServerReporter = new JsTestServer.JasmineDriver.Reporter();
35
+ jasmineEnv.addReporter(jsTestServerReporter);
36
+ jasmineEnv.addReporter(new jasmine.JsApiReporter());
37
+ jasmine.TrivialReporter.prototype.log = function() {
38
+ if (window.console && window.console.log) window.console.log.apply(window.console, arguments);
39
+ };
40
+ jasmineEnv.addReporter(new jasmine.TrivialReporter());
41
+
42
+ window.onload = function() {
43
+ jasmineEnv.execute();
44
+ }
45
+ };
46
+
47
+ JsTestServer.JasmineDriver.Reporter = function() {
48
+ this.console = "";
49
+ this.finished = false;
50
+ this.runnerState = "running";
51
+ };
52
+ JsTestServer.JasmineDriver.Reporter.prototype.log = function(str) {
53
+ this.console += (str + "\n");
54
+ };
55
+ JsTestServer.JasmineDriver.Reporter.prototype.reportRunnerResults = function(runner) {
56
+ this.finished = true;
57
+ if (runner.results().failedCount == 0) {
58
+ this.runnerState = "passed";
59
+ } else {
60
+ this.runnerState = "failed";
61
+ }
62
+ }
63
+ })(JsTestServer.JasmineDriver.Instance);
@@ -0,0 +1,28 @@
1
+ (function() {
2
+ JsTestServer.RemoteControl = function() {
3
+ };
4
+
5
+ JsTestServer.RemoteControl.start = function() {
6
+ var instance = new JsTestServer.RemoteControl();
7
+ instance.start();
8
+ };
9
+
10
+ JsTestServer.RemoteControl.prototype.start = function() {
11
+ this.poll();
12
+ };
13
+
14
+ JsTestServer.RemoteControl.prototype.poll = function() {
15
+ var self = this;
16
+ JsTestServer.xhrGet("/remote_control/commands", function(request) {
17
+ if(request.status == 200) {
18
+ var messages = eval(request.responseText);
19
+ for(var i=0; i < messages.length; i++) {
20
+ eval(messages[i].javascript);
21
+ }
22
+ setTimeout(function() {
23
+ self.poll();
24
+ }, 100);
25
+ };
26
+ });
27
+ };
28
+ })();
@@ -0,0 +1,31 @@
1
+ (function($) {
2
+ var jsTestServerStatus = {"runner_state": "running", "console": ""};
3
+
4
+ JsTestServer.status = function() {
5
+ return JsTestServer.JSON.stringify(jsTestServerStatus);
6
+ };
7
+
8
+ $(Screw).bind('after', function() {
9
+ var error_text = $(".error").map(function(_i, error_element) {
10
+ var element = $(error_element);
11
+
12
+ var parent_descriptions = element.parents("li.describe");
13
+ var parent_description_text = [];
14
+
15
+ for(var i=parent_descriptions.length-1; i >= 0; i--) {
16
+ parent_description_text.push($(parent_descriptions[i]).find("h1").text());
17
+ }
18
+
19
+ var it_text = element.parents("li.it").find("h2").text();
20
+
21
+ return parent_description_text.join(" ") + " " + it_text + ": " + element.text();
22
+ }).get().join("\\n");
23
+
24
+ jsTestServerStatus["console"] = error_text;
25
+ if(error_text) {
26
+ jsTestServerStatus["runner_state"] = "failed";
27
+ } else {
28
+ jsTestServerStatus["runner_state"] = "passed";
29
+ }
30
+ });
31
+ })(jQuery);
@@ -0,0 +1,8 @@
1
+ require "rubygems"
2
+ require "uri"
3
+ require "curb"
4
+
5
+ Curl::Easy.http_post(
6
+ "http://localhost:8080/remote_control/commands",
7
+ "javascript=#{URI.encode("alert('hey you')")}"
8
+ )
@@ -0,0 +1,21 @@
1
+ # Project-specific configuration for CruiseControl.rb
2
+ Project.configure do |project|
3
+
4
+ # Send email notifications about broken and fixed builds to email1@your.site, email2@your.site (default: send to nobody)
5
+ # project.email_notifier.emails = ['email1@your.site', 'email2@your.site']
6
+
7
+ # Set email 'from' field to john@doe.com:
8
+ # project.email_notifier.from = 'john@doe.com'
9
+
10
+ # Build the project by invoking rake task 'custom'
11
+ project.rake_task = 'jasmine:test:ci:saucelabs'
12
+
13
+ # Build the project by invoking shell script "build_my_app.sh". Keep in mind that when the script is invoked,
14
+ # current working directory is <em>[cruise&nbsp;data]</em>/projects/your_project/work, so if you do not keep build_my_app.sh
15
+ # in version control, it should be '../build_my_app.sh' instead
16
+ #project.build_command = 'cp ../saucelabs.yml .'
17
+
18
+ # Ping Subversion for new revisions every 5 minutes (default: 30 seconds)
19
+ # project.scheduler.polling_interval = 5.minutes
20
+
21
+ end
@@ -0,0 +1,44 @@
1
+ class JasmineHelper
2
+ def self.jasmine_lib_dir
3
+ File.expand_path(File.join(jasmine_root, 'lib'))
4
+ end
5
+
6
+ def self.jasmine
7
+ ['/lib/' + File.basename(Dir.glob("#{JasmineHelper.jasmine_lib_dir}/jasmine*.js").first)] +
8
+ ['/lib/json2.js',
9
+ '/lib/TrivialReporter.js']
10
+ end
11
+
12
+ def self.jasmine_root
13
+ File.expand_path(File.join(File.dirname(__FILE__), '..'))
14
+ end
15
+
16
+
17
+ def self.jasmine_src_dir
18
+ File.expand_path(File.join(jasmine_root, 'src'))
19
+ end
20
+
21
+ def self.jasmine_lib_dir
22
+ File.expand_path(File.join(jasmine_root, 'lib'))
23
+ end
24
+
25
+ def self.jasmine_spec_dir
26
+ File.expand_path(File.join(jasmine_root, 'spec'))
27
+ end
28
+
29
+ def self.raw_spec_files
30
+ Dir.glob(File.join(jasmine_spec_dir, "**/*[Ss]pec.js"))
31
+ end
32
+
33
+ def self.specs
34
+ Jasmine.cachebust(raw_spec_files).collect {|f| f.sub(jasmine_spec_dir, "/spec")}
35
+ end
36
+
37
+ def self.dir_mappings
38
+ {
39
+ "/src" => jasmine_src_dir,
40
+ "/spec" => jasmine_spec_dir,
41
+ "/lib" => jasmine_lib_dir
42
+ }
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "jasmine_helper.rb"))
3
+ require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
4
+
5
+ jasmine_runner = if ENV['SAUCELABS'] == 'true'
6
+ require 'sauce_tunnel'
7
+ require 'selenium_config'
8
+ Jasmine::SauceLabsRunner.new(JasmineHelper.specs,
9
+ JasmineHelper.dir_mappings,
10
+ :saucelabs_config => 'saucelabs',
11
+ :saucelabs_config_file => File.expand_path(File.join(File.dirname(__FILE__), "saucelabs.yml")))
12
+ else
13
+ require "selenium_rc"
14
+ Jasmine::Runner.new(SeleniumRC::Server.new('localhost').jar_path,
15
+ JasmineHelper.specs,
16
+ JasmineHelper.dir_mappings)
17
+ end
18
+
19
+ spec_builder = Jasmine::SpecBuilder.new(JasmineHelper.raw_spec_files, jasmine_runner)
20
+
21
+ should_stop = false
22
+
23
+ Spec::Runner.configure do |config|
24
+ config.after(:suite) do
25
+ spec_builder.stop if should_stop
26
+ end
27
+ end
28
+
29
+ spec_builder.start
30
+ should_stop = true
31
+ spec_builder.declare_suites
@@ -0,0 +1,55 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require "spec/autorun"
4
+ require "selenium_rc"
5
+ require "thin"
6
+ dir = File.dirname(__FILE__)
7
+ LIBRARY_ROOT_DIR = File.expand_path("#{dir}/../..")
8
+ require File.expand_path("#{dir}/../spec_helpers/be_http")
9
+ require File.expand_path("#{dir}/../spec_helpers/show_test_exceptions")
10
+ require File.expand_path("#{dir}/../spec_helpers/wait_for")
11
+ require "#{dir}/functional_spec_server_starter"
12
+ ARGV.push("-b")
13
+
14
+ Spec::Runner.configure do |config|
15
+ config.mock_with :rr
16
+ end
17
+
18
+ Sinatra::Application.use ShowTestExceptions
19
+ Sinatra::Application.set :raise_errors, true
20
+
21
+ Sinatra::Application.use(JsTestServer::Server::App)
22
+
23
+ class Spec::ExampleGroup
24
+ include WaitFor
25
+
26
+ def self.start_servers(framework_name)
27
+ before(:all) do
28
+ server = SeleniumRC::Server.new("0.0.0.0", "4444")
29
+ unless server.service_is_running?
30
+ worker = fork do
31
+ server.boot
32
+ exit!
33
+ end
34
+ end
35
+ trap("INT") do
36
+ server.stop
37
+ end
38
+ at_exit do
39
+ server.stop
40
+ end
41
+
42
+ FunctionalSpecServerStarter.new(framework_name).call
43
+ TCPSocket.wait_for_service :host => "0.0.0.0", :port => "4444"
44
+ end
45
+
46
+ after(:suite) do
47
+ FunctionalSpecServerStarter.new(framework_name).stop_thin_server
48
+ end
49
+ end
50
+
51
+
52
+ def root_url
53
+ "http://#{JsTestServer::Server::DEFAULTS[:host]}:#{JsTestServer::Server::DEFAULTS[:port]}"
54
+ end
55
+ end
@@ -0,0 +1,69 @@
1
+ require "rubygems"
2
+ require "timeout"
3
+ require "lsof"
4
+ dir = File.dirname(__FILE__)
5
+ $LOAD_PATH.unshift "#{dir}/../../lib"
6
+ require "js_test_server"
7
+ require "nokogiri"
8
+
9
+ class FunctionalSpecServerStarter
10
+ include WaitFor
11
+
12
+ attr_reader :framework_name
13
+ def initialize(framework_name)
14
+ @framework_name = framework_name
15
+ end
16
+
17
+ def call(threaded=true)
18
+ return if $js_test_server_started
19
+
20
+ Lsof.kill(8080)
21
+ wait_for do
22
+ !Lsof.running?(8080)
23
+ end
24
+
25
+ dir = File.dirname(__FILE__)
26
+ Dir.chdir("#{dir}/../../") do
27
+ Thread.start do
28
+ start_thin_server
29
+ end
30
+ end
31
+
32
+ wait_for do
33
+ Lsof.running?(8080)
34
+ end
35
+ $js_test_server_started = true
36
+ end
37
+
38
+ def start_thin_server
39
+ system("bin/js-test-server --spec-path=#{spec_path} --root-path=#{root_path} --framework-name=#{framework_name} --framework-path=#{framework_path}")
40
+ at_exit do
41
+ stop_thin_server
42
+ end
43
+ end
44
+
45
+ def stop_thin_server
46
+ Lsof.kill(8080)
47
+ end
48
+
49
+ def framework_path
50
+ File.expand_path("#{dir}/../frameworks/#{framework_name}/lib")
51
+ end
52
+
53
+ def spec_path
54
+ File.expand_path("#{dir}/#{framework_name}/example_spec")
55
+ end
56
+
57
+ def root_path
58
+ File.expand_path("#{dir}/../example_root")
59
+ end
60
+
61
+ def dir
62
+ dir = File.dirname(__FILE__)
63
+ end
64
+ end
65
+
66
+ if $0 == __FILE__
67
+ FunctionalSpecServerStarter.new(ENV["FRAMEWORK_PATH"] || "jasmine").call(false)
68
+ sleep
69
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../functional_spec_helper")
2
+
3
+ describe JsTestServer do
4
+ start_servers("jasmine")
5
+ attr_reader :stdout, :request
6
+
7
+ before do
8
+ @stdout = StringIO.new
9
+ JsTestServer::Client.const_set(:STDOUT, stdout)
10
+ @request = "http request"
11
+ end
12
+
13
+ after do
14
+ JsTestServer::Client.__send__(:remove_const, :STDOUT)
15
+ end
16
+
17
+ it "runs a full passing Suite" do
18
+ JsTestServer::Client::Runner.run(:spec_url => "#{root_url}/specs/passing_spec")
19
+ stdout.string.strip.should include(JsTestServer::Client::PASSED_RUNNER_STATE.capitalize)
20
+ end
21
+
22
+ it "runs a full failing Suite" do
23
+ JsTestServer::Client::Runner.run(:spec_url => "#{root_url}/specs/failing_spec")
24
+ stdout.string.strip.should include(JsTestServer::Client::FAILED_RUNNER_STATE.capitalize)
25
+ stdout.string.strip.should include("A failing spec fails")
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../functional_spec_helper")
2
+
3
+ describe JsTestServer do
4
+ start_servers("screw-unit")
5
+ attr_reader :stdout, :request
6
+
7
+ before do
8
+ @stdout = StringIO.new
9
+ JsTestServer::Client.const_set(:STDOUT, stdout)
10
+ @request = "http request"
11
+ end
12
+
13
+ after do
14
+ JsTestServer::Client.__send__(:remove_const, :STDOUT)
15
+ end
16
+
17
+ it "runs a full passing Suite" do
18
+ JsTestServer::Client::Runner.run(:spec_url => "#{root_url}/specs/passing_spec")
19
+ stdout.string.strip.should == JsTestServer::Client::PASSED_RUNNER_STATE.capitalize
20
+ end
21
+
22
+ it "runs a full failing Suite" do
23
+ JsTestServer::Client::Runner.run(:spec_url => "#{root_url}/specs/failing_spec")
24
+ stdout.string.strip.should include(JsTestServer::Client::FAILED_RUNNER_STATE.capitalize)
25
+ stdout.string.strip.should include("A failing spec fails: expected true to equal false")
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ class FunctionalSuite
2
+ def run(framework_name)
3
+ dir = File.dirname(__FILE__)
4
+ Dir["#{dir}/functional/#{framework_name}/**/*_spec.rb"].each do |file|
5
+ require file
6
+ end
7
+ end
8
+ end
9
+
10
+ ["jasmine", "screw-unit"].each do |framework_name|
11
+ pid = fork do
12
+ FunctionalSuite.new.run(framework_name)
13
+ end
14
+ Process.wait(pid)
15
+ $?.success? || raise("#{framework_name} suite failed")
16
+ end
@@ -0,0 +1,32 @@
1
+ module BeHttp
2
+ include Spec::Matchers
3
+ def be_http(status, headers, body)
4
+ SimpleMatcher.new(nil) do |given, matcher|
5
+ description = (<<-DESC).gsub(/^ +/, "")
6
+ be an http of
7
+ expected status: #{status.inspect}
8
+ actual status : #{given.status.inspect}
9
+
10
+ expected headers containing: #{headers.inspect}
11
+ actual headers : #{given.headers.inspect}
12
+
13
+ expected body containing: #{body.inspect}
14
+ actual body : #{given.body.inspect}
15
+ DESC
16
+ matcher.failure_message = description
17
+ matcher.negative_failure_message = "not #{description}"
18
+
19
+ passed = true
20
+ unless given.status == status
21
+ passed = false
22
+ end
23
+ unless headers.all?{|k, v| given.headers[k] == headers[k]}
24
+ passed = false
25
+ end
26
+ unless body.is_a?(Regexp) ? given.body =~ body : given.body.include?(body)
27
+ passed = false
28
+ end
29
+ passed
30
+ end
31
+ end
32
+ end