honkster-js-test-server 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +40 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +60 -0
- data/README.markdown +9 -0
- data/Rakefile +67 -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 +130 -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/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 +77 -0
- data/lib/js_test_server/server/standalone.ru +1 -0
- data/lib/js_test_server/server/views.rb +12 -0
- data/lib/js_test_server/server/views/dir.html.rb +22 -0
- data/lib/js_test_server/server/views/frameworks.rb +3 -0
- data/lib/js_test_server/server/views/not_found.html.rb +13 -0
- data/lib/js_test_server/server/views/page.html.rb +40 -0
- data/lib/js_test_server/server/views/remote_control_subscriber.rb +17 -0
- data/lib/js_test_server/server/views/suite.html.rb +54 -0
- data/lib/js_test_server/server/views/suites.rb +6 -0
- data/lib/js_test_server/server/views/suites/jasmine.html.rb +30 -0
- data/lib/js_test_server/server/views/suites/screw_unit.html.rb +44 -0
- data/public/js_test_server.js +565 -0
- data/public/js_test_server/jasmine_driver.js +63 -0
- data/public/js_test_server/remote_control.js +28 -0
- data/public/js_test_server/screw_unit_driver.js +31 -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 +103 -0
- data/spec/unit/unit_spec_helper.rb +34 -0
- data/spec/unit_suite.rb +10 -0
- data/vendor/lucky-luciano/lib/lucky_luciano.rb +5 -0
- data/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +142 -0
- data/vendor/lucky-luciano/lib/lucky_luciano/resource/path.rb +24 -0
- data/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
- data/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
- data/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +276 -0
- data/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
- data/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
- metadata +146 -0
@@ -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/views"
|
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
|
@@ -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::Views::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 = Views::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, {}, Views::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
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class JsTestServer::Server::Resources::Resource < LuckyLuciano::Resource
|
2
|
+
protected
|
3
|
+
|
4
|
+
def spec_path; server.spec_path; end
|
5
|
+
def root_path; server.root_path; end
|
6
|
+
def framework_path; server.framework_path; end
|
7
|
+
def root_url; server.root_url; end
|
8
|
+
|
9
|
+
def server
|
10
|
+
JsTestServer::Configuration
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class JsTestServer::Server::Resources::SpecFile < JsTestServer::Server::Resources::File
|
2
|
+
map "/specs"
|
3
|
+
|
4
|
+
get "/?" do
|
5
|
+
do_get
|
6
|
+
end
|
7
|
+
|
8
|
+
get "*" do
|
9
|
+
do_get
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def do_get
|
15
|
+
if ::File.exists?(absolute_path)
|
16
|
+
if ::File.directory?(absolute_path)
|
17
|
+
spec_files = ::Dir["#{absolute_path}/**/*.js"].map do |file|
|
18
|
+
["#{relative_path}#{file.gsub(absolute_path, "")}"]
|
19
|
+
end
|
20
|
+
get_generated_spec(absolute_path, spec_files)
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
elsif ::File.exists?("#{absolute_path}.js")
|
25
|
+
get_generated_spec("#{absolute_path}.js", ["#{relative_path}.js"])
|
26
|
+
else
|
27
|
+
pass
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_generated_spec(real_path, spec_files)
|
32
|
+
html = render_spec(spec_files)
|
33
|
+
headers = {
|
34
|
+
'Content-Type' => "text/html",
|
35
|
+
'Last-Modified' => ::File.mtime(real_path).rfc822
|
36
|
+
}
|
37
|
+
[200, headers, html]
|
38
|
+
end
|
39
|
+
|
40
|
+
def render_spec(spec_files)
|
41
|
+
JsTestServer.suite_view_class.new(:spec_files => spec_files, :framework_path => framework_path).to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def absolute_path
|
45
|
+
@absolute_path ||= ::File.expand_path("#{spec_path}#{relative_path.gsub(%r{^/specs}, "")}")
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class JsTestServer::Server::Resources::WebRoot < JsTestServer::Server::Resources::File
|
2
|
+
map "/"
|
3
|
+
|
4
|
+
get("") do
|
5
|
+
"<html><head></head><body>Welcome to the Js Test Server. Click the following link to run you <a href=/specs>spec suite</a>.</body></html>"
|
6
|
+
end
|
7
|
+
|
8
|
+
get("*") do
|
9
|
+
do_get
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def root_path
|
15
|
+
JsTestServer::Configuration.js_test_server_root_path
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class JsTestServer::Server::Runner
|
2
|
+
include JsTestServer::Server
|
3
|
+
def cli(*argv)
|
4
|
+
opts = Trollop.options(argv) do
|
5
|
+
opt(
|
6
|
+
:framework_name,
|
7
|
+
"The name of the test framework you want to use. e.g. --framework-name=jasmine",
|
8
|
+
:type => String,
|
9
|
+
:default => DEFAULTS[:framework_name]
|
10
|
+
)
|
11
|
+
opt(
|
12
|
+
:framework_path,
|
13
|
+
"The name of the test framework you want to use. e.g. --framework-path=./specs/jasmine_core",
|
14
|
+
:type => String,
|
15
|
+
:default => DEFAULTS[:framework_path]
|
16
|
+
)
|
17
|
+
opt(
|
18
|
+
:spec_path,
|
19
|
+
"The path to the spec files. e.g. --spec-path=./specs",
|
20
|
+
:type => String,
|
21
|
+
:default => DEFAULTS[:spec_path]
|
22
|
+
)
|
23
|
+
opt(
|
24
|
+
:root_path,
|
25
|
+
"The root path of the server. e.g. --root-path=./public",
|
26
|
+
:type => String,
|
27
|
+
:default => DEFAULTS[:root_path]
|
28
|
+
)
|
29
|
+
opt(
|
30
|
+
:port,
|
31
|
+
"The server port",
|
32
|
+
:type => Integer,
|
33
|
+
:default => DEFAULTS[:port]
|
34
|
+
)
|
35
|
+
opt(
|
36
|
+
:javascript_files,
|
37
|
+
"The javascript files under test",
|
38
|
+
:type => String,
|
39
|
+
:default => ""
|
40
|
+
)
|
41
|
+
opt(
|
42
|
+
:css_files,
|
43
|
+
"The css files under test",
|
44
|
+
:type => String,
|
45
|
+
:default => ""
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
JsTestServer.port = opts[:port]
|
50
|
+
JsTestServer.framework_name = opts[:framework_name]
|
51
|
+
JsTestServer.framework_path = opts[:framework_path]
|
52
|
+
JsTestServer.spec_path = opts[:spec_path]
|
53
|
+
JsTestServer.root_path = opts[:root_path]
|
54
|
+
suite_view_class = JsTestServer::Configuration.instance.suite_view_class
|
55
|
+
suite_view_class.project_js_files.push(*opts[:javascript_files].split(","))
|
56
|
+
suite_view_class.project_css_files.push(*opts[:css_files].split(","))
|
57
|
+
STDOUT.puts "root-path is #{JsTestServer.root_path}"
|
58
|
+
STDOUT.puts "spec-path is #{JsTestServer.spec_path}"
|
59
|
+
start
|
60
|
+
end
|
61
|
+
|
62
|
+
def start
|
63
|
+
require "thin"
|
64
|
+
Thin::Runner.new([
|
65
|
+
"--port", JsTestServer.port.to_s,
|
66
|
+
"--rackup", File.expand_path(JsTestServer.rackup_path),
|
67
|
+
"start"]
|
68
|
+
).run!
|
69
|
+
end
|
70
|
+
|
71
|
+
def standalone_rackup(rack_builder)
|
72
|
+
require "sinatra"
|
73
|
+
|
74
|
+
rack_builder.use JsTestServer::Server::App
|
75
|
+
rack_builder.run Sinatra::Application
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
JsTestServer::Server::Runner.new.standalone_rackup(self)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
module JsTestServer::Server::Views
|
4
|
+
end
|
5
|
+
|
6
|
+
require "#{dir}/views/page.html"
|
7
|
+
require "#{dir}/views/not_found.html"
|
8
|
+
require "#{dir}/views/suite.html"
|
9
|
+
require "#{dir}/views/dir.html"
|
10
|
+
require "#{dir}/views/frameworks"
|
11
|
+
require "#{dir}/views/suites"
|
12
|
+
require "#{dir}/views/remote_control_subscriber"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class JsTestServer::Server::Views::Dir < JsTestServer::Server::Views::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
|