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
This commit is contained in:
Sean McGivern 2017-05-03 09:27:03 +00:00
commit 6201f4c2b5
2 changed files with 13 additions and 2 deletions

View file

@ -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

View file

@ -1,11 +1,15 @@
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!