let's run with a server, like all the cool kids do nowadays\!
This commit is contained in:
parent
ed4590ee44
commit
5d43eb2193
@ -71,7 +71,7 @@ void Runner::loadSpec()
|
||||
outputFiles.enqueue(outputFile);
|
||||
}
|
||||
|
||||
page.mainFrame()->load(QUrl::fromLocalFile(runnerFiles.dequeue()));
|
||||
page.mainFrame()->load(runnerFiles.dequeue());
|
||||
ticker.start();
|
||||
}
|
||||
|
||||
|
7
features/bin/with_server.feature
Normal file
7
features/bin/with_server.feature
Normal file
@ -0,0 +1,7 @@
|
||||
Feature: Bin - With Server
|
||||
Scenario: Run using an HTTP server
|
||||
Given there is no existing "spec/report.txt" file
|
||||
When I run `bin/jasmine-headless-webkit --use-server -j spec/jasmine/success/success.yml -f File:spec/report.txt`
|
||||
Then the exit status should be 0
|
||||
And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage
|
||||
|
@ -18,7 +18,8 @@ module Jasmine
|
||||
:enable_cache => true,
|
||||
:files => [],
|
||||
:reporters => [ [ 'Console' ] ],
|
||||
:quiet => false
|
||||
:quiet => false,
|
||||
:use_server => false
|
||||
}
|
||||
|
||||
DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit')
|
||||
@ -75,6 +76,8 @@ module Jasmine
|
||||
@options[:seed] = arg.to_i
|
||||
when '--format', '-f'
|
||||
add_reporter(arg)
|
||||
when '--use-server'
|
||||
@options[:use_server] = true
|
||||
when '--out'
|
||||
add_reporter_file(arg)
|
||||
when '-h', '--help'
|
||||
@ -107,6 +110,7 @@ module Jasmine
|
||||
[ '--seed', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--out', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--use-server', GetoptLong::NO_ARGUMENT ],
|
||||
[ '-h', '--help', GetoptLong::NO_ARGUMENT ],
|
||||
[ '-q', '--quiet', GetoptLong::NO_ARGUMENT ]
|
||||
)
|
||||
@ -165,8 +169,9 @@ module Jasmine
|
||||
[ '--runner-out <filename>', 'Write runner to specified filename' ],
|
||||
[ '-j, --jasmine-config <config file>', 'Jasmine Yaml config to use' ],
|
||||
[ '--no-full-run', 'Do not perform a full spec run after a successful targeted spec run' ],
|
||||
[ '--use-server', 'Load tests from an HTTP server instead of from filesystem' ],
|
||||
[ '-l, --list', 'List files in the order they will be required' ],
|
||||
[ '--seed', 'Random order seed for spec file ordering' ],
|
||||
[ '--seed <seed>', 'Random order seed for spec file ordering' ],
|
||||
[ '-f, --format <reporter<:filename>>', 'Specify an output reporter and possibly output filename' ],
|
||||
[ '--out <filename>', 'Specify output filename for last defined reporter' ],
|
||||
[ '-q, --quiet', "Silence most non-test related warnings" ],
|
||||
|
@ -7,7 +7,6 @@ require 'yaml'
|
||||
require 'erb'
|
||||
require 'sprockets'
|
||||
|
||||
|
||||
module Jasmine
|
||||
module Headless
|
||||
class Runner
|
||||
@ -63,7 +62,11 @@ module Jasmine
|
||||
command << "-r #{file}"
|
||||
end
|
||||
|
||||
command += targets.flatten.collect { |target| File.expand_path(target) }
|
||||
command += targets.flatten.collect do |target|
|
||||
target = File.expand_path(target)
|
||||
target = server_uri + target if options[:use_server]
|
||||
target
|
||||
end
|
||||
|
||||
command.compact.join(' ')
|
||||
end
|
||||
@ -83,7 +86,13 @@ module Jasmine
|
||||
end
|
||||
end
|
||||
|
||||
system jasmine_command(run_targets)
|
||||
runner = lambda { system jasmine_command(run_targets) }
|
||||
|
||||
if options[:use_server]
|
||||
wrap_in_server(&runner)
|
||||
else
|
||||
runner.call
|
||||
end
|
||||
|
||||
@_status = $?.exitstatus
|
||||
ensure
|
||||
@ -111,7 +120,54 @@ module Jasmine
|
||||
)
|
||||
end
|
||||
|
||||
def wrap_in_server
|
||||
require 'rack'
|
||||
require 'webrick'
|
||||
require 'thread'
|
||||
require 'net/http'
|
||||
|
||||
server = Thread.new do
|
||||
responder = lambda do |env|
|
||||
file = Pathname(env['PATH_INFO'])
|
||||
|
||||
if file.file?
|
||||
[ 200, { 'Content-Type' => 'text/html' }, [ file.read ] ]
|
||||
else
|
||||
[ 404, {}, [ 'Not found' ] ]
|
||||
end
|
||||
end
|
||||
|
||||
Rack::Handler::WEBrick.run(responder, :Port => server_port, :Logger => Logger.new(StringIO.new), :AccessLog => [ nil, nil ])
|
||||
end
|
||||
|
||||
while true do
|
||||
begin
|
||||
Net::HTTP.get(URI(server_uri))
|
||||
break
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
end
|
||||
|
||||
sleep 0.1
|
||||
end
|
||||
|
||||
yield
|
||||
|
||||
Thread.kill(server)
|
||||
end
|
||||
|
||||
private
|
||||
def server_port
|
||||
@server_port ||= 21000 + rand(1000)
|
||||
end
|
||||
|
||||
def server_interface
|
||||
'127.0.0.1'
|
||||
end
|
||||
|
||||
def server_uri
|
||||
"http://#{server_interface}:#{server_port}"
|
||||
end
|
||||
|
||||
def jasmine_config_data
|
||||
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])
|
||||
|
||||
|
@ -100,6 +100,18 @@ describe Jasmine::Headless::Runner do
|
||||
it_should_have_basics
|
||||
it { should include("-q") }
|
||||
end
|
||||
|
||||
context 'server' do
|
||||
let(:server_uri) { 'server uri' }
|
||||
|
||||
before do
|
||||
options[:use_server] = true
|
||||
|
||||
runner.stubs(:server_uri).returns(server_uri)
|
||||
end
|
||||
|
||||
it { should include(server_uri + File.expand_path(target)) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#runner_filename' do
|
||||
|
Loading…
Reference in New Issue
Block a user