Class: JsTestServer::Server::Runner

Inherits:
Object
  • Object
show all
Includes:
JsTestServer::Server
Defined in:
lib/js_test_server/server/runner.rb

Constant Summary

Constants included from JsTestServer::Server

DEFAULTS

Instance Method Summary collapse

Instance Method Details

#cli(*argv) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/js_test_server/server/runner.rb', line 3

def cli(*argv)
  opts = Trollop.options(argv) do
    opt(
      :framework_name,
      "The name of the test framework you want to use. e.g. --framework-name=jasmine",
      :type => String,
      :default => DEFAULTS[:framework_name]
    )
    opt(
      :framework_path,
      "The name of the test framework you want to use. e.g. --framework-path=./specs/jasmine_core",
      :type => String,
      :default => DEFAULTS[:framework_path]
    )
    opt(
      :spec_path,
      "The path to the spec files. e.g. --spec-path=./specs",
      :type => String,
      :default => DEFAULTS[:spec_path]
    )
    opt(
      :root_path,
      "The root path of the server. e.g. --root-path=./public",
      :type => String,
      :default => DEFAULTS[:root_path]
    )
    opt(
      :port,
      "The server port",
      :type => Integer,
      :default => DEFAULTS[:port]
    )
    opt(
      :javascript_files,
      "The javascript files under test",
      :type => String,
      :default => ""
    )
    opt(
      :css_files,
      "The css files under test",
      :type => String,
      :default => ""
    )
    opt(
      :javascript_test_file_glob,
      "The glob to find the javascript files",
      :type => String,
      :default => DEFAULTS[:javascript_test_file_glob]
    )
  end

  JsTestServer.port = opts[:port]
  JsTestServer.framework_name = opts[:framework_name]
  JsTestServer.framework_path = opts[:framework_path]
  JsTestServer.spec_path = opts[:spec_path]
  JsTestServer.root_path = opts[:root_path]
  JsTestServer.javascript_test_file_glob = opts[:javascript_test_file_glob]
  suite_view_class = JsTestServer::Configuration.instance.suite_view_class
  suite_view_class.project_js_files.push(*opts[:javascript_files].split(","))
  suite_view_class.project_css_files.push(*opts[:css_files].split(","))
  STDOUT.puts "root-path is #{JsTestServer.root_path}"
  STDOUT.puts "spec-path is #{JsTestServer.spec_path}"
  start
end

#standalone_rackup(rack_builder) ⇒ Object



78
79
80
81
82
83
# File 'lib/js_test_server/server/runner.rb', line 78

def standalone_rackup(rack_builder)
  require "sinatra"

  rack_builder.use JsTestServer::Server::App
  rack_builder.run Sinatra::Application
end

#startObject



69
70
71
72
73
74
75
76
# File 'lib/js_test_server/server/runner.rb', line 69

def start
  require "thin"
  Thin::Runner.new([
    "--port", JsTestServer.port.to_s,
    "--rackup", File.expand_path(JsTestServer.rackup_path),
    "start"]
  ).run!
end