added 260907 version of worker toolkit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# Most of the config here, and in cuprite_config, was borrowed, with many thanks, from:
|
||||
# https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing
|
||||
Capybara.configure do |config|
|
||||
# Usually, especially when using Selenium, developers tend to increase the max wait time.
|
||||
# With Cuprite, there is no need for that.
|
||||
# We use a Capybara default value here explicitly.
|
||||
config.default_max_wait_time = 2
|
||||
|
||||
# Normalize whitespaces when using `has_text?` and similar matchers,
|
||||
# i.e., ignore newlines, trailing spaces, etc.
|
||||
# That makes tests less dependent on slightly UI changes.
|
||||
config.default_normalize_ws = true
|
||||
|
||||
# Where to store system tests artifacts (e.g. screenshots, downloaded files, etc.).
|
||||
# It could be useful to be able to configure this path from the outside (e.g., on CI).
|
||||
config.save_path = ENV.fetch("CAPYBARA_ARTIFACTS", "./tmp/capybara")
|
||||
|
||||
# Port on which to fire up the rails backend.
|
||||
config.server_port = ENV["SYSTEM_SPEC_BACKEND_PORT"]
|
||||
|
||||
# Where to find frontend app; see ./frontend_app.rb
|
||||
config.app_host = "http://localhost:#{ENV["SYSTEM_SPEC_FRONTEND_PORT"]}"
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
require "capybara/cuprite"
|
||||
|
||||
Capybara.register_driver(:cuprite) do |app|
|
||||
Capybara::Cuprite::Driver.new(
|
||||
app,
|
||||
window_size: [1200, 800],
|
||||
browser_options: {},
|
||||
process_timeout: 10,
|
||||
inspector: true,
|
||||
headless: ENV["HEADLESS_CHROME"] != "false"
|
||||
)
|
||||
end
|
||||
|
||||
Capybara.default_driver = Capybara.javascript_driver = :cuprite
|
||||
@@ -0,0 +1,76 @@
|
||||
module SystemSpec
|
||||
class FrontendApp
|
||||
include Singleton
|
||||
|
||||
def start(log = "/dev/null")
|
||||
if test_connection_to_frontend_app
|
||||
puts "Frontend app already running at #{frontend_app_url}"
|
||||
return
|
||||
end
|
||||
|
||||
puts "Starting frontend app at #{frontend_app_url}"
|
||||
@pid ||= Process.spawn(
|
||||
frontend_app_cmd,
|
||||
[:out, :err] => log,
|
||||
:chdir => "../frontend"
|
||||
)
|
||||
|
||||
timeout = 15.seconds
|
||||
unless test_connection_to_frontend_app(timeout)
|
||||
fail "Frontend app did not start within #{timeout} seconds"
|
||||
end
|
||||
end
|
||||
|
||||
def wait_on
|
||||
return unless @pid
|
||||
Process.wait @pid
|
||||
end
|
||||
|
||||
def stop
|
||||
return unless @pid
|
||||
Process.kill "QUIT", @pid
|
||||
Process.wait @pid
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def test_connection_to_frontend_app(timeout = 0)
|
||||
system(
|
||||
test_connection_cmd(timeout),
|
||||
out: "/dev/null"
|
||||
)
|
||||
end
|
||||
|
||||
def test_connection_cmd(timeout)
|
||||
[
|
||||
"curl --silent --head -X GET",
|
||||
"--retry-connrefused",
|
||||
"--retry", timeout.to_s,
|
||||
"--retry-delay", "1",
|
||||
frontend_app_url
|
||||
].join(" ")
|
||||
end
|
||||
|
||||
def frontend_app_cmd
|
||||
[
|
||||
"PORT=#{backend_port}",
|
||||
"BASE_URL=#{frontend_app_url}",
|
||||
"FRONTEND_PORT=#{frontend_port}",
|
||||
"./node_modules/.bin/ember", "serve",
|
||||
"--port", frontend_port
|
||||
].join(" ")
|
||||
end
|
||||
|
||||
def frontend_app_url
|
||||
"http://localhost:#{frontend_port}"
|
||||
end
|
||||
|
||||
def frontend_port
|
||||
ENV["SYSTEM_SPEC_FRONTEND_PORT"]
|
||||
end
|
||||
|
||||
def backend_port
|
||||
ENV["SYSTEM_SPEC_BACKEND_PORT"]
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user