提交 6201f4c2 编写于 作者: S Sean McGivern

Merge branch '29836-try-waiting-for-ajax-in-addition-to-requests' into 'master'

Wait for AJAX requests at the JS level in addition to wait for requests at the middleware level

Closes #29836

See merge request !10688
......@@ -10,7 +10,7 @@ if ENV['CI']
Knapsack::Adapters::SpinachAdapter.bind
end
%w(select2_helper test_env repo_helpers wait_for_ajax sidekiq).each do |f|
%w(select2_helper test_env repo_helpers wait_for_ajax wait_for_requests sidekiq).each do |f|
require Rails.root.join('spec', 'support', f)
end
......@@ -30,6 +30,13 @@ Spinach.hooks.before_run do
include FactoryGirl::Syntax::Methods
end
Spinach.hooks.after_feature do |feature_data|
if feature_data.scenarios.flat_map(&:tags).include?('javascript')
include WaitForRequests
wait_for_requests_complete
end
end
module StdoutReporterWithScenarioLocation
# Override the standard reporter to show filename and line number next to each
# scenario for easy, focused re-runs
......
require_relative './wait_for_ajax'
module WaitForRequests
extend self
include WaitForAjax
# This is inspired by http://www.salsify.com/blog/engineering/tearing-capybara-ajax-tests
def wait_for_requests_complete
Gitlab::Testing::RequestBlockerMiddleware.block_requests!
wait_for('pending AJAX requests complete') do
Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero?
Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? &&
finished_all_ajax_requests?
end
ensure
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册