Skip to content

Commit

Permalink
Store command and display it if server fails
Browse files Browse the repository at this point in the history
This should help out people experiencing "server not responding"
due to their configuration throwing an exception
  • Loading branch information
nathanstitt committed Dec 21, 2014
1 parent 7ad7cbe commit 77eec92
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions lib/guard/jasmine/server.rb
Expand Up @@ -7,13 +7,15 @@

module Guard
class Jasmine

# Start and stop a Jasmine test server for requesting the specs
# from PhantomJS.
#
module Server
class << self
attr_accessor :process

attr_accessor :process
attr_accessor :cmd
# Start the internal test server for getting the Jasmine runner.
#
# @param [Hash] options the server options
Expand Down Expand Up @@ -106,15 +108,7 @@ def start_rack_server(server, port, options)
coverage = options[:coverage] ? 'on' : 'off'

::Guard::UI.info "Guard::Jasmine starts #{ server } spec server on port #{ port } in #{ environment } environment (coverage #{ coverage })."

self.process = ChildProcess.build(*['rackup', '-E', environment.to_s, '-p', port.to_s, '-s', server.to_s, rackup_config].compact)
process.environment['COVERAGE'] = options[:coverage].to_s
process.environment['IGNORE_INSTRUMENTATION'] = options[:ignore_instrumentation].to_s
process.io.inherit! if options[:verbose]
process.start

rescue => e
::Guard::UI.error "Cannot start Rack server: #{ e.message }"
self.start( ['rackup', '-E', environment.to_s, '-p', port.to_s,'-s', server.to_s, rackup_config] )
end

# Start the Rack server of the current project. This
Expand All @@ -130,14 +124,7 @@ def start_unicorn_server(port, options)
coverage = options[:coverage] ? 'on' : 'off'

::Guard::UI.info "Guard::Jasmine starts Unicorn spec server on port #{ port } in #{ environment } environment (coverage #{ coverage })."

self.process = ChildProcess.build('unicorn_rails', '-E', environment.to_s, '-p', port.to_s)
process.environment['COVERAGE'] = options[:coverage].to_s
process.io.inherit! if options[:verbose]
process.start

rescue => e
::Guard::UI.error "Cannot start Unicorn server: #{ e.message }"
execute(['unicorn_rails', '-E', environment.to_s, '-p', port.to_s])
end

# Start the Jasmine gem server of the current project.
Expand All @@ -148,15 +135,23 @@ def start_unicorn_server(port, options)
#
def start_rake_server(port, task, options)
::Guard::UI.info "Guard::Jasmine starts Jasmine Gem test server on port #{ port }."
execute( ['ruby', '-S', 'rake', task, "JASMINE_PORT=#{ port }"] )
end

self.process = ChildProcess.build('ruby', '-S', 'rake', task, "JASMINE_PORT=#{ port }")
# Builds a child process with the given command and arguments
# @param [Array<string>] array of arguments to send to ChildProcess
def execute(cmd)
self.cmd = cmd
self.process = ChildProcess.build(*self.cmd)
process.environment['COVERAGE'] = options[:coverage].to_s
process.environment['IGNORE_INSTRUMENTATION'] = options[:ignore_instrumentation].to_s
process.io.inherit! if options[:verbose]
process.start

rescue => e
::Guard::UI.error "Cannot start Rake task server: #{ e.message }"
::Guard::UI.error "Cannot start server using command #{ cmd.join(' ') }."
::Guard::UI.error "Error was: #{ e.message }"
end

# Wait until the Jasmine test server is running.
#
# @param [Number] port the server port
Expand All @@ -176,10 +171,18 @@ def wait_for_server(port, timeout)
end

rescue Timeout::Error
::Guard::UI.warning 'Timeout while waiting for the server startup. You may need to increase the `:server_timeout` option.'
throw :task_has_failed
::Guard::UI.warning "Timeout while waiting for the server to startup"
::Guard::UI.warning "Most likely there is a configuration error that's preventing the server from starting"
::Guard::UI.warning "You may need to increase the `:server_timeout` option."
::Guard::UI.warning "The commandline that was used to start the server was:"
::Guard::UI.warning self.cmd.join(' ' )
::Guard::UI.warning "You should attempt to run that and see if any errors occur"

throw :task_has_failed
end

end
end

end
end

0 comments on commit 77eec92

Please sign in to comment.