-
Notifications
You must be signed in to change notification settings - Fork 73
/
Rakefile
74 lines (60 loc) · 2.22 KB
/
Rakefile
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
require "rubygems"
require "bundler/setup"
load "tasks/resque.rake"
task "resque:setup" => :environment
task :environment do
$LOAD_PATH.unshift "lib"
require "printer/configuration"
require "printer/jobs"
end
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs = ["test"]
t.pattern = "test/**/*_test.rb"
t.warning = false
end
task :default => [:test, "test:javascript"]
namespace :data do
desc "Clear out the data"
task :reset do
$LOAD_PATH.unshift "lib"
require "printer/data_store"
Printer::DataStore.redis.keys.each { |k| Printer::DataStore.redis.del k }
end
end
namespace :test do
desc "Run javascript tests"
task :javascript => :environment do
phantomjs_requirement = Gem::Requirement.new(">= 1.3.0")
phantomjs_version = Gem::Version.new(`phantomjs --version`.match(/\d+\.\d+\.\d+/)[0]) rescue Gem::Version.new("0.0.0")
unless phantomjs_requirement.satisfied_by?(phantomjs_version)
STDERR.puts "Your version of phantomjs (v#{phantomjs_version}) is not compatible with the current phantom-driver.js."
STDERR.puts "Please upgrade your version of phantomjs to #{phantomjs_requirement} and re-run this task."
exit 1
end
require "webrick"
test_port = 3100
server = WEBrick::HTTPServer.new(:Port => test_port, :DocumentRoot => File.expand_path("../test/javascript", __FILE__), :AccessLog => [], :Logger => WEBrick::Log.new("/dev/null", 7))
server.mount("/app", WEBrick::HTTPServlet::FileHandler, File.expand_path("../public", __FILE__))
server_thread = Thread.new do
puts "Starting the server on http://127.0.0.1:#{test_port}"
server.start
end
runner = "http://127.0.0.1:#{test_port}/test.html"
phantom_driver = File.expand_path('../test/javascript/phantom-driver.js', __FILE__)
command = "phantomjs #{phantom_driver} #{runner}"
puts "Running: #{command}"
IO.popen(command) do |test|
puts test.read
end
# grab the exit status of phantomjs
# this will be the result of the tests
# it is important to grab it before we
# exit the server otherwise $? will be overwritten.
test_result = $?.exitstatus
puts "Stopping the server"
server.stop
server_thread.join
exit test_result
end
end