diff options
Diffstat (limited to 'spec/support/wait_for_requests.rb')
-rw-r--r-- | spec/support/wait_for_requests.rb | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/spec/support/wait_for_requests.rb b/spec/support/wait_for_requests.rb index 73da23391ee..05ec9026141 100644 --- a/spec/support/wait_for_requests.rb +++ b/spec/support/wait_for_requests.rb @@ -1,20 +1,31 @@ -require_relative './wait_for_ajax' +require_relative './wait_for_requests' 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 + def block_and_wait_for_requests_complete Gitlab::Testing::RequestBlockerMiddleware.block_requests! - wait_for('pending AJAX requests complete') do - Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? && - finished_all_ajax_requests? + wait_for('pending requests complete') do + Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? end ensure Gitlab::Testing::RequestBlockerMiddleware.allow_requests! end + def wait_for_requests + wait_for('JS requests') { finished_all_requests? } + end + + private + + def finished_all_requests? + return true unless javascript_test? + + finished_all_ajax_requests? && + finished_all_vue_resource_requests? + end + # Waits until the passed block returns true def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, polling_interval: 0.01) wait_until = Time.now + max_wait_time.seconds @@ -27,10 +38,24 @@ module WaitForRequests end end end + + def finished_all_vue_resource_requests? + page.evaluate_script('window.activeVueResources || 0').zero? + end + + def finished_all_ajax_requests? + return true if page.evaluate_script('typeof jQuery === "undefined"') + + page.evaluate_script('jQuery.active').zero? + end + + def javascript_test? + Capybara.current_driver == Capybara.javascript_driver + end end RSpec.configure do |config| config.after(:each, :js) do - wait_for_requests_complete + block_and_wait_for_requests_complete end end |