qunit: Also clear $.timers when stopping unfinished animations
[lhc/web/wiklou.git] / tests / qunit / data / testrunner.js
index cef5c15..a947484 100644 (file)
@@ -1,8 +1,8 @@
-/* global CompletenessTest, sinon */
+/* global sinon */
 ( function ( $, mw, QUnit ) {
        'use strict';
 
-       var mwTestIgnore, addons;
+       var addons;
 
        /**
         * Add bogus to url to prevent IE crazy caching
                value: 'true'
        } );
 
-       /**
-        * CompletenessTest
-        *
-        * Adds toggle checkbox to header
-        */
-       QUnit.config.urlConfig.push( {
-               id: 'completenesstest',
-               label: 'Run CompletenessTest',
-               tooltip: 'Run the completeness test'
-       } );
-
        /**
         * SinonJS
         *
                };
        }() );
 
-       // Initiate when enabled
-       if ( QUnit.urlParams.completenesstest ) {
-
-               // Return true to ignore
-               mwTestIgnore = function ( val, tester ) {
-
-                       // Don't record methods of the properties of constructors,
-                       // to avoid getting into a loop (prototype.constructor.prototype..).
-                       // Since we're therefor skipping any injection for
-                       // "new mw.Foo()", manually set it to true here.
-                       if ( val instanceof mw.Map ) {
-                               tester.methodCallTracker.Map = true;
-                               return true;
-                       }
-                       if ( val instanceof mw.Title ) {
-                               tester.methodCallTracker.Title = true;
-                               return true;
-                       }
-
-                       // Don't record methods of the properties of a jQuery object
-                       if ( val instanceof $ ) {
-                               return true;
-                       }
-
-                       // Don't iterate over the module registry (the 'script' references would
-                       // be listed as untested methods otherwise)
-                       if ( val === mw.loader.moduleRegistry ) {
-                               return true;
-                       }
-
-                       return false;
-               };
-
-               // eslint-disable-next-line no-new
-               new CompletenessTest( mw, mwTestIgnore );
-       }
-
        /**
         * Reset mw.config and others to a fresh copy of the live config for each test(),
         * and restore it back to the live one afterwards.
                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() {
                                        // 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;
                                                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 ) {
                                                        );
                                                } );
                                                // Force animations to stop to give the next test a clean start
+                                               $.timers = [];
                                                $.fx.stop();
 
                                                throw new Error( 'Unfinished animations: ' + timers );
                                                        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 = [];