Commit 6201f4c2 authored by Sean McGivern's avatar 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
parents f930c66e 11ad7444
...@@ -10,7 +10,7 @@ if ENV['CI'] ...@@ -10,7 +10,7 @@ if ENV['CI']
Knapsack::Adapters::SpinachAdapter.bind Knapsack::Adapters::SpinachAdapter.bind
end 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) require Rails.root.join('spec', 'support', f)
end end
...@@ -30,6 +30,13 @@ Spinach.hooks.before_run do ...@@ -30,6 +30,13 @@ Spinach.hooks.before_run do
include FactoryGirl::Syntax::Methods include FactoryGirl::Syntax::Methods
end 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 module StdoutReporterWithScenarioLocation
# Override the standard reporter to show filename and line number next to each # Override the standard reporter to show filename and line number next to each
# scenario for easy, focused re-runs # scenario for easy, focused re-runs
......
require_relative './wait_for_ajax'
module WaitForRequests module WaitForRequests
extend self extend self
include WaitForAjax
# This is inspired by http://www.salsify.com/blog/engineering/tearing-capybara-ajax-tests # This is inspired by http://www.salsify.com/blog/engineering/tearing-capybara-ajax-tests
def wait_for_requests_complete def wait_for_requests_complete
Gitlab::Testing::RequestBlockerMiddleware.block_requests! Gitlab::Testing::RequestBlockerMiddleware.block_requests!
wait_for('pending AJAX requests complete') do 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 end
ensure ensure
Gitlab::Testing::RequestBlockerMiddleware.allow_requests! Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment