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
@@ -0,0 +1,12 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
module JsTestServer::Server::Representations
|
4
|
+
end
|
5
|
+
|
6
|
+
require "#{dir}/representations/page.html"
|
7
|
+
require "#{dir}/representations/not_found.html"
|
8
|
+
require "#{dir}/representations/suite.html"
|
9
|
+
require "#{dir}/representations/dir.html"
|
10
|
+
require "#{dir}/representations/frameworks"
|
11
|
+
require "#{dir}/representations/suites"
|
12
|
+
require "#{dir}/representations/remote_control_subscriber"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class JsTestServer::Server::Representations::Dir < JsTestServer::Server::Representations::Page
|
2
|
+
needs :relative_path, :absolute_path
|
3
|
+
attr_reader :relative_path, :absolute_path
|
4
|
+
protected
|
5
|
+
|
6
|
+
def body_content
|
7
|
+
ul do
|
8
|
+
::Dir.glob("#{absolute_path}/*").inject("") do |html, file|
|
9
|
+
li do
|
10
|
+
a(
|
11
|
+
::File.basename(file),
|
12
|
+
:href => "#{relative_path}/#{::File.basename(file)}".gsub("//", "/")
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def title_text
|
20
|
+
"Contents of #{relative_path}"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class JsTestServer::Server::Representations::Page < Erector::Widget
|
2
|
+
def content(&block)
|
3
|
+
rawtext %Q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">}
|
4
|
+
html :xmlns => "http://www.w3.org/1999/xhtml", :"xml:lang" => "en" do
|
5
|
+
head do
|
6
|
+
meta :"http-equiv" => "Content-Type", :content => "text/html;charset=UTF-8"
|
7
|
+
title title_text
|
8
|
+
head_content
|
9
|
+
end
|
10
|
+
body do
|
11
|
+
body_content(&block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def head_content
|
19
|
+
end
|
20
|
+
|
21
|
+
def title_text
|
22
|
+
"Js Test Server"
|
23
|
+
end
|
24
|
+
|
25
|
+
def body_content(&block)
|
26
|
+
yield(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def path
|
30
|
+
helpers.rack_request.path_info
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module JsTestServer
|
2
|
+
module Server
|
3
|
+
module Representations
|
4
|
+
class RemoteControlSubscriber < JsTestServer::Server::Representations::Page
|
5
|
+
def head_content
|
6
|
+
javascript :src => "/js_test_server.js"
|
7
|
+
javascript :src => "/js_test_server/remote_control.js"
|
8
|
+
javascript "JsTestServer.RemoteControl.start();"
|
9
|
+
end
|
10
|
+
|
11
|
+
def body_content
|
12
|
+
a "Commands", :href => Resources::RemoteControl.path("commands"), :id => "commands"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class JsTestServer::Server::Representations::Suite < JsTestServer::Server::Representations::Page
|
2
|
+
class << self
|
3
|
+
def project_js_files
|
4
|
+
@@project_js_files ||= []
|
5
|
+
end
|
6
|
+
|
7
|
+
def project_js_files=(files)
|
8
|
+
@@project_js_files = files
|
9
|
+
end
|
10
|
+
|
11
|
+
def project_css_files
|
12
|
+
@@project_css_files ||= []
|
13
|
+
end
|
14
|
+
|
15
|
+
def project_css_files=(files)
|
16
|
+
@@project_css_files = files
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
needs :spec_files
|
21
|
+
attr_reader :spec_files
|
22
|
+
protected
|
23
|
+
|
24
|
+
def title_text
|
25
|
+
"Js Test Core Suite"
|
26
|
+
end
|
27
|
+
|
28
|
+
def head_content
|
29
|
+
project_js_files
|
30
|
+
project_css_files
|
31
|
+
spec_script_elements
|
32
|
+
end
|
33
|
+
|
34
|
+
def spec_script_elements
|
35
|
+
spec_files.each do |file|
|
36
|
+
script :type => "text/javascript", :src => file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def project_js_files
|
41
|
+
self.class.project_js_files.each do |file|
|
42
|
+
script :src => file, :type => "text/javascript"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def project_css_files
|
47
|
+
self.class.project_css_files.each do |file|
|
48
|
+
link :href => file, :type => "text/css", :media => "screen", :rel => "stylesheet"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def body_content
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class JsTestServer::Server::Representations::Suites::Jasmine < JsTestServer::Server::Representations::Suite
|
2
|
+
needs :spec_files, :framework_path
|
3
|
+
attr_reader :spec_files, :framework_path
|
4
|
+
|
5
|
+
def title_text
|
6
|
+
"Jasmine suite"
|
7
|
+
end
|
8
|
+
|
9
|
+
def head_content
|
10
|
+
core_js_files
|
11
|
+
project_js_files
|
12
|
+
link :rel => "stylesheet", :href => "/framework/jasmine.css"
|
13
|
+
project_css_files
|
14
|
+
spec_script_elements
|
15
|
+
script <<-JS
|
16
|
+
JsTestServer.JasmineDriver.init();
|
17
|
+
JS
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def core_js_files
|
22
|
+
jasmine_file = File.basename(Dir["#{framework_path}/jasmine*.js"].last)
|
23
|
+
javascript :src => "/framework/#{jasmine_file}"
|
24
|
+
javascript :src => "/framework/TrivialReporter.js"
|
25
|
+
javascript :src => "/js_test_server.js"
|
26
|
+
javascript :src => "/js_test_server/jasmine_driver.js"
|
27
|
+
end
|
28
|
+
|
29
|
+
def body_content
|
30
|
+
div :id => "jasmine_content"
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class JsTestServer::Server::Representations::Suites::ScrewUnit < JsTestServer::Server::Representations::Suite
|
2
|
+
class << self
|
3
|
+
def jquery_js_file
|
4
|
+
@jquery_js_file ||= "/framework/jquery-1.3.2.js"
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_writer :jquery_js_file
|
8
|
+
end
|
9
|
+
|
10
|
+
needs :spec_files, :framework_path
|
11
|
+
attr_reader :spec_files, :framework_path
|
12
|
+
|
13
|
+
def title_text
|
14
|
+
"Screw Unit suite"
|
15
|
+
end
|
16
|
+
|
17
|
+
def head_content
|
18
|
+
core_js_files
|
19
|
+
project_js_files
|
20
|
+
link :rel => "stylesheet", :href => "/framework/screw.css"
|
21
|
+
project_css_files
|
22
|
+
|
23
|
+
spec_script_elements
|
24
|
+
end
|
25
|
+
|
26
|
+
def core_js_files
|
27
|
+
javascript :src => jquery_js_file
|
28
|
+
javascript :src => "/js_test_server.js"
|
29
|
+
javascript :src => "/framework/jquery.fn.js"
|
30
|
+
javascript :src => "/framework/jquery.print.js"
|
31
|
+
javascript :src => "/framework/screw.builder.js"
|
32
|
+
javascript :src => "/framework/screw.matchers.js"
|
33
|
+
javascript :src => "/framework/screw.events.js"
|
34
|
+
javascript :src => "/framework/screw.behaviors.js"
|
35
|
+
javascript :src => "/js_test_server/screw_unit_driver.js"
|
36
|
+
end
|
37
|
+
|
38
|
+
def jquery_js_file
|
39
|
+
self.class.jquery_js_file
|
40
|
+
end
|
41
|
+
|
42
|
+
def body_content
|
43
|
+
div :id => "screw_unit_content"
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
module JsTestServer::Server::Resources
|
4
|
+
end
|
5
|
+
|
6
|
+
require "#{dir}/resources/resource"
|
7
|
+
require "#{dir}/resources/file"
|
8
|
+
require "#{dir}/resources/spec_file"
|
9
|
+
require "#{dir}/resources/framework_file"
|
10
|
+
require "#{dir}/resources/web_root"
|
11
|
+
require "#{dir}/resources/not_found"
|
12
|
+
require "#{dir}/resources/remote_control"
|
13
|
+
|
14
|
+
require "#{dir}/resources/implementations_deprecation"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class JsTestServer::Server::Resources::File < JsTestServer::Server::Resources::Resource
|
2
|
+
def self.render_file(absolute_path)
|
3
|
+
extension = ::File.extname(absolute_path)
|
4
|
+
content_type = MIME_TYPES[extension] || 'text/html'
|
5
|
+
headers = {
|
6
|
+
'Content-Type' => content_type,
|
7
|
+
'Last-Modified' => ::File.mtime(absolute_path).rfc822
|
8
|
+
}
|
9
|
+
[200, headers, ::File.read(absolute_path)]
|
10
|
+
end
|
11
|
+
|
12
|
+
map "*"
|
13
|
+
|
14
|
+
MIME_TYPES = {
|
15
|
+
'.html' => 'text/html',
|
16
|
+
'.htm' => 'text/html',
|
17
|
+
'.js' => 'text/javascript',
|
18
|
+
'.css' => 'text/css',
|
19
|
+
'.png' => 'image/png',
|
20
|
+
'.jpg' => 'image/jpeg',
|
21
|
+
'.jpeg' => 'image/jpeg',
|
22
|
+
'.gif' => 'image/gif',
|
23
|
+
}
|
24
|
+
|
25
|
+
get "*" do
|
26
|
+
do_get
|
27
|
+
end
|
28
|
+
|
29
|
+
def relative_path
|
30
|
+
@relative_path ||= request.path_info
|
31
|
+
end
|
32
|
+
|
33
|
+
def absolute_path
|
34
|
+
@absolute_path ||= ::File.expand_path("#{root_path}#{relative_path}")
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def do_get
|
40
|
+
if ::File.exists?(absolute_path)
|
41
|
+
if ::File.directory?(absolute_path)
|
42
|
+
render_dir
|
43
|
+
else
|
44
|
+
render_file
|
45
|
+
end
|
46
|
+
else
|
47
|
+
pass
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def render_dir
|
52
|
+
JsTestServer::Server::Representations::Dir.new(:relative_path => relative_path, :absolute_path => absolute_path).to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def render_file
|
56
|
+
self.class.render_file(absolute_path)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class JsTestServer::Server::Resources::FrameworkFile < JsTestServer::Server::Resources::File
|
2
|
+
map "/framework"
|
3
|
+
|
4
|
+
get "/?" do
|
5
|
+
do_get
|
6
|
+
end
|
7
|
+
|
8
|
+
get "*" do
|
9
|
+
do_get
|
10
|
+
end
|
11
|
+
|
12
|
+
def absolute_path
|
13
|
+
@absolute_path ||= ::File.expand_path("#{framework_path}#{relative_path.gsub(%r{^/framework}, "")}")
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class JsTestServer::Server::Resources::ImplementationsDeprecation < JsTestServer::Server::Resources::Resource
|
2
|
+
map "/implementations"
|
3
|
+
|
4
|
+
get "*" do
|
5
|
+
new_path = JsTestServer::Server::Resources::File.path("javascripts", *params["splat"])
|
6
|
+
[301, {'Location' => new_path}, "This page has been moved to #{new_path}"]
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class JsTestServer::Server::Resources::NotFound < JsTestServer::Server::Resources::Resource
|
2
|
+
include JsTestServer::Server
|
3
|
+
map "*"
|
4
|
+
|
5
|
+
get "/" do
|
6
|
+
call
|
7
|
+
end
|
8
|
+
|
9
|
+
put "/" do
|
10
|
+
call
|
11
|
+
end
|
12
|
+
|
13
|
+
post "/" do
|
14
|
+
call
|
15
|
+
end
|
16
|
+
|
17
|
+
delete "/" do
|
18
|
+
call
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
body = Representations::NotFound.new(:message => "File #{request.path_info} not found").to_s
|
23
|
+
[ 404, { "Content-Type" => "text/html" }, body ]
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module JsTestServer
|
2
|
+
module Server
|
3
|
+
module Resources
|
4
|
+
class RemoteControl < JsTestServer::Server::Resources::Resource
|
5
|
+
class Queue
|
6
|
+
def initialize
|
7
|
+
@items = []
|
8
|
+
@subscriber = nil
|
9
|
+
end
|
10
|
+
def push item
|
11
|
+
@items << item
|
12
|
+
notify_subscriber if @subscriber
|
13
|
+
end
|
14
|
+
alias :<< :push
|
15
|
+
def subscribe &blk
|
16
|
+
@subscriber = blk
|
17
|
+
notify_subscriber unless @items.empty?
|
18
|
+
end
|
19
|
+
def unsubscribe
|
20
|
+
@subscriber = nil
|
21
|
+
end
|
22
|
+
def clear
|
23
|
+
items, @items = @items, []
|
24
|
+
items
|
25
|
+
end
|
26
|
+
def to_a
|
27
|
+
@items
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def notify_subscriber
|
33
|
+
@subscriber.call
|
34
|
+
unsubscribe
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
def queue
|
40
|
+
@queue ||= Queue.new
|
41
|
+
end
|
42
|
+
attr_writer :queue
|
43
|
+
end
|
44
|
+
|
45
|
+
map "/remote_control"
|
46
|
+
|
47
|
+
get "subscriber" do
|
48
|
+
[200, {}, Representations::RemoteControlSubscriber.new.to_s]
|
49
|
+
end
|
50
|
+
|
51
|
+
post "commands" do
|
52
|
+
self.class.queue << {"javascript" => params["javascript"]}
|
53
|
+
[200, {'Content-Type' => "application/json"}, self.class.queue.to_a.to_json]
|
54
|
+
end
|
55
|
+
|
56
|
+
get "commands" do
|
57
|
+
if Object.const_defined?(:Thin)
|
58
|
+
subscribed = true
|
59
|
+
self.class.queue.subscribe do
|
60
|
+
subscribed = false
|
61
|
+
env[Thin::Request::ASYNC_CALLBACK].call(do_get_commands)
|
62
|
+
end
|
63
|
+
env[Thin::Request::ASYNC_CLOSE].callback do
|
64
|
+
self.class.queue.unsubscribe if subscribed
|
65
|
+
end
|
66
|
+
throw :async
|
67
|
+
else
|
68
|
+
do_get_commands
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
def do_get_commands
|
74
|
+
queue_content = self.class.queue.clear
|
75
|
+
[200, {'Content-Type' => "application/json"}, queue_content.to_json]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|