Skip to content

Instantly share code, notes, and snippets.

@tatey
Created April 11, 2014 11:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatey/10459627 to your computer and use it in GitHub Desktop.
Save tatey/10459627 to your computer and use it in GitHub Desktop.
script/e2e
#!/usr/bin/env ruby
#
# End to end tests.
#
# Starts the application server and BrowserStack tunnel in the background
# and then runs protractor. Stops the server and tunnel after protractor
# finishes.
require 'bundler/setup'
require 'dotenv'
require 'tmpdir'
Dotenv.load
APP_PORT = 4000
APP_DEST = Dir.mktmpdir
BS_KEY = ENV.fetch 'BROWSERSTACK_KEY'
CI = ENV.fetch 'CI', 'false'
def spawn_and_block_until_ready command, ready
p_read, p_write = IO.pipe
pid = Process.spawn command, out: p_write
while line = p_read.gets do
puts line
break if line.include? ready
end
pid
end
# Start the application server.
spawn_and_block_until_ready "#{__dir__}/serve --port #{APP_PORT} --destination #{APP_DEST}", 'Auto-regeneration: enabled'
# Start the BrowserStack tunnel.
spawn_and_block_until_ready "#{__dir__}/../bin/browser_stack_tunnel #{BS_KEY} localhost,#{APP_PORT},0", 'Press Ctrl-C to exit'
# Run protractor and wait until it finishes.
status = nil
scripts = [
"#{__dir__}/../bin/protractor #{__dir__}/../config/protractor/iframe.conf.ie8.js",
"#{__dir__}/../bin/protractor #{__dir__}/../config/protractor/iframe.conf.safari.js",
"#{__dir__}/../bin/protractor #{__dir__}/../config/protractor/iframe.conf.firefox.js",
"#{__dir__}/../bin/protractor #{__dir__}/../config/protractor/iframe.conf.chrome.js",
"#{__dir__}/../bin/protractor #{__dir__}/../config/protractor/window.conf.chrome.js"
]
scripts.each do |script|
pid = Process.spawn script
status = Process.waitpid2(pid)[1]
if !status.success?
puts "Script exited with a non-zero exit status: #{script}"
break
end
end
FileUtils.rm_r APP_DEST
# Gracefully exit, killing all the descendent processes we spawned.
if CI == 'true'
exit status.exitstatus
else
Signal.trap 'INT' do
Process.exit status.exitstatus
end
Process.kill 'INT', -Process.getpgrp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment