From: Timo Tijhof Date: Sat, 15 Apr 2017 00:12:06 +0000 (-0700) Subject: qunit: Improve testrunner logging for pending ajax X-Git-Tag: 1.31.0-rc.0~3506^2 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=d8af25c706ac5b3b18bccbf76f8669c5b73764c9;p=lhc%2Fweb%2Fwiklou.git qunit: Improve testrunner logging for pending ajax * Move `restoreWarnings()` in tearDown() to the mirrored location of related code in setUp(). * Ensure that accidentally calling `suppressWarnings()` twice will not wipe out the original reference indefinitely. If it was already set, subsequent calls should do nothing instead of overwriting them again so that recovery is still possible. * Log all ajax requests logged during the test, not just the one currently still pending. This should avoid situations where we throw "Pending ajax requests" but no information is logged about which requests those might be. Change-Id: I900ad98c4c8520bdd6ae00a24ac82272f3becfee --- diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index b0118afbec..55bd27656d 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -131,9 +131,11 @@ liveMessages = mw.messages; function suppressWarnings() { - warn = mw.log.warn; - error = mw.log.error; - mw.log.warn = mw.log.error = $.noop; + if ( warn === undefined ) { + warn = mw.log.warn; + error = mw.log.error; + mw.log.warn = mw.log.error = $.noop; + } } function restoreWarnings() { @@ -215,6 +217,10 @@ // Stop tracking ajax requests $( document ).off( 'ajaxSend', trackAjax ); + // As a convenience feature, automatically restore warnings if they're + // still suppressed by the end of the test. + restoreWarnings(); + // Farewell, mock environment! mw.config = liveConfig; mw.messages = liveMessages; @@ -223,10 +229,6 @@ messages: liveMessages } ); - // As a convenience feature, automatically restore warnings if they're - // still suppressed by the end of the test. - restoreWarnings(); - // Tests should use fake timers or wait for animations to complete // Check for incomplete animations/requests/etc and throw if there are any. if ( $.timers && $.timers.length !== 0 ) { @@ -253,8 +255,11 @@ mw.log.warn( 'Pending requests does not match jQuery.active count' ); } // Force requests to stop to give the next test a clean start - $.each( pending, function ( i, ajax ) { - mw.log.warn( 'Pending AJAX request #' + i, ajax.options ); + $.each( ajaxRequests, function ( i, ajax ) { + mw.log.warn( + 'AJAX request #' + i + ' (state: ' + ajax.xhr.state() + ')', + ajax.options + ); ajax.xhr.abort(); } ); ajaxRequests = [];