mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 11:33:44 +08:00
b1b53da71d
Previously, calling `sign_in` would cause the browser to be redirected to `/`, and would cause the Ember app to boot. We would then call `visit()`, causing the app to boot for a second time. This commit adds a `redirect=false` option to the `/session/username/become` route. This avoids the unnecessary boot of the app, and leads to significantly faster system spec run times. In local testing, this takes the full system-spec suite for chat from ~6min to ~4min.
61 lines
1.6 KiB
Ruby
61 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
require "highline/import"
|
|
|
|
module SystemHelpers
|
|
def pause_test
|
|
result =
|
|
ask(
|
|
"\n\e[33mTest paused, press enter to resume, type `d` and press enter to start debugger.\e[0m",
|
|
)
|
|
binding.pry if result == "d" # rubocop:disable Lint/Debugger
|
|
self
|
|
end
|
|
|
|
def sign_in(user)
|
|
visit "/session/#{user.encoded_username}/become.json?redirect=false"
|
|
end
|
|
|
|
def sign_out
|
|
delete "/session"
|
|
end
|
|
|
|
def setup_system_test
|
|
SiteSetting.login_required = false
|
|
SiteSetting.content_security_policy = false
|
|
SiteSetting.force_hostname = Capybara.server_host
|
|
SiteSetting.port = Capybara.server_port
|
|
SiteSetting.external_system_avatars_enabled = false
|
|
end
|
|
|
|
def try_until_success(timeout: 2, frequency: 0.01)
|
|
start ||= Time.zone.now
|
|
backoff ||= frequency
|
|
yield
|
|
rescue RSpec::Expectations::ExpectationNotMetError
|
|
raise if Time.zone.now >= start + timeout.seconds
|
|
sleep backoff
|
|
backoff += frequency
|
|
retry
|
|
end
|
|
|
|
def resize_window(width: nil, height: nil)
|
|
original_size = page.driver.browser.manage.window.size
|
|
page.driver.browser.manage.window.resize_to(width || original_size.width, height || original_size.height)
|
|
yield
|
|
ensure
|
|
page.driver.browser.manage.window.resize_to(original_size.width, original_size.height)
|
|
end
|
|
|
|
def using_browser_timezone(timezone, &example)
|
|
previous_browser_timezone = ENV["TZ"]
|
|
|
|
ENV["TZ"] = timezone
|
|
|
|
Capybara.using_session(timezone) do
|
|
freeze_time(&example)
|
|
end
|
|
|
|
ENV["TZ"] = previous_browser_timezone
|
|
end
|
|
end
|