Use native ES5 Array prototype methods instead of jQuery
[lhc/web/wiklou.git] / tests / qunit / data / testrunner.js
index 929fa1f..5943294 100644 (file)
@@ -2,7 +2,7 @@
 ( function ( $, mw, QUnit ) {
        'use strict';
 
-       var addons;
+       var addons, nested;
 
        /**
         * Make a safe copy of localEnv:
@@ -77,8 +77,8 @@
        ( function () {
                var orgModule = QUnit.module;
                QUnit.module = function ( name, localEnv, executeNow ) {
-                       var orgBeforeEach, orgAfterEach;
-                       if ( QUnit.config.moduleStack.length ) {
+                       var orgBeforeEach, orgAfterEach, orgExecute;
+                       if ( nested ) {
                                // In a nested module, don't re-run our handlers.
                                return orgModule.apply( this, arguments );
                        }
                                executeNow = localEnv;
                                localEnv = undefined;
                        }
+                       if ( executeNow ) {
+                               // Wrap executeNow() so that we can detect nested modules
+                               orgExecute = executeNow;
+                               executeNow = function () {
+                                       var ret;
+                                       nested = true;
+                                       ret = orgExecute.apply( this, arguments );
+                                       nested = false;
+                                       return ret;
+                               };
+                       }
 
                        localEnv = localEnv || {};
                        orgBeforeEach = localEnv.beforeEach;
                var orgModule = QUnit.module;
                QUnit.module = function ( name, localEnv, executeNow ) {
                        var orgBeforeEach, orgAfterEach;
-                       if ( QUnit.config.moduleStack.length ) {
+                       if ( nested ) {
                                // In a nested module, don't re-run our handlers.
                                return orgModule.apply( this, arguments );
                        }
                                        // Test should use fake XHR, wait for requests, or call abort()
                                        $activeLen = $.active;
                                        if ( $activeLen !== undefined && $activeLen !== 0 ) {
-                                               pending = $.grep( ajaxRequests, function ( ajax ) {
+                                               pending = ajaxRequests.filter( function ( ajax ) {
                                                        return ajax.xhr.state() === 'pending';
                                                } );
                                                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( ajaxRequests, function ( i, ajax ) {
+                                               ajaxRequests.forEach( function ( ajax, i ) {
                                                        mw.log.warn(
                                                                'AJAX request #' + i + ' (state: ' + ajax.xhr.state() + ')',
                                                                ajax.options