From ba681a6fec0a84bb8bcdd9225e6d07a24ce62dcf Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 4 Aug 2015 17:11:11 -0700 Subject: [PATCH] qunit: Improved unfinished ajax detection Sometimes $.active is non-zero but the ajaxRequests array doesn't contain any pending requests (yet). In that case, log $.active as well. Change-Id: I1c181b1234d1f883605de38805bc029c064a1f5b --- tests/qunit/data/testrunner.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index 41754b45c1..78771decd0 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -246,7 +246,7 @@ }, teardown: function () { - var timers, active; + var timers, pending, $activeLen; localEnv.teardown.call( this ); @@ -278,21 +278,22 @@ } // Test should use fake XHR, wait for requests, or call abort() - if ( $.active !== undefined && $.active !== 0 ) { - active = $.grep( ajaxRequests, function ( ajax ) { + $activeLen = $.active; + if ( $activeLen !== undefined && $activeLen !== 0 ) { + pending = $.grep( ajaxRequests, function ( ajax ) { return ajax.xhr.state() === 'pending'; } ); - if ( active.length !== $.active ) { + if ( pending.length !== $activeLen ) { mw.log.warn( 'Pending requests does not match jQuery.active count' ); } // Force requests to stop to give the next test a clean start - $.each( active, function ( i, ajax ) { - mw.log.warn( 'Unfinished AJAX request #' + i, ajax.options ); + $.each( pending, function ( i, ajax ) { + mw.log.warn( 'Pending AJAX request #' + i, ajax.options ); ajax.xhr.abort(); } ); ajaxRequests = []; - throw new Error( 'Unfinished AJAX requests: ' + active.length ); + throw new Error( 'Pending AJAX requests: ' + pending.length + ' (active: ' + $activeLen + ')' ); } } }; -- 2.20.1