-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjspawnspec
More file actions
executable file
·130 lines (118 loc) · 2.61 KB
/
Copy pathjspawnspec
File metadata and controls
executable file
·130 lines (118 loc) · 2.61 KB
1
2
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'json'
class Color
RESET="\e[0m"
BLACK="30"
RED="31"
GREEN="32"
YELLOW="33"
BLUE="34"
MAGENTA="35"
CYAN="36"
WHITE="37"
BLACKBG="40"
REDBG="41"
GREENBG="42"
YELLOWBG="43"
BLUEBG="44"
MAGENTABG="45"
CYANBG="46"
WHITEBG="47"
BOLD="1"
FAINT="2" # Doesn't work in xterm
ITALIC="3" # Doesn't work in xterm
BLINK="5"
RAPID="6" # Doesn't work in xterm
CONCEALED="8"
SUB="48" # Doesn't work in xterm
SUPER="49" # Doesn't work in xterm
def Color.prepare(message, colors=nil)
msg = ""
if colors
msg = "\e["
colors.split(" ").each_with_index do |c,i|
msg += ";" if i
msg += eval c.upcase
end
msg += "m"
end
msg += message
if colors
msg += "\e[0m"
end
msg
end
def Color.puts(message, colors=nil)
puts Color.prepare(message, colors)
end
def Color.print(message, colors=nil)
print Color.prepare(message, colors)
end
end
def startDaemonIfNotStarted
if 0 == %x{ps ax | egrep -v 'egrep' | egrep -c 'node ./jspawnspecd'}.to_i
puts "Starting jSpawnSpec Daemon"
fork do
%x{./jspawnspecd}
end
else
puts "jSpawnSpec Daemon Already Started"
end
end
def getSpecPaths(paths)
absolute_paths = []
paths.each do |file|
if File.exists? file
if File.directory? file
absolute_paths << Dir.glob("#{file}/**/*.js").map {|f| File.expand_path(f)}
else
absolute_paths << File.expand_path(file)
end
end
end
absolute_paths.flatten
end
def startSpecs(specs)
response = false
while !response
begin
Net::HTTP.start("localhost", 27182) do |http|
@session_id = JSON.parse(http.get("/start").body)["session_id"]
response = true
specs.each do |spec|
http.get("/test/#{@session_id}#{spec}")
end
end
rescue StandardError
end
end
end
def pollForResults(number_of_specs)
while 0 != number_of_specs
begin
Net::HTTP.start("localhost", 27182) do |http|
results = JSON.parse(http.get("/results/#{@session_id}").body)["results"]
puts results.inspect
results.each do |result|
result.results.each do |spec|
if (spec)
Color.print(".", Color.GREEN)
else
Color.print(".", Color.RED)
end
end
number_of_specs -= 1
end
end
rescue StandardError
end
sleep 1
end
end
puts "(in #{Dir.pwd})"
startDaemonIfNotStarted
specs_to_run = getSpecPaths(ARGV)
startSpecs(specs_to_run)
pollForResults(specs_to_run.length)