( function ( $, mw, QUnit ) {
'use strict';
- var mwTestIgnore, mwTester,
- addons,
- ELEMENT_NODE = 1,
- TEXT_NODE = 3;
+ var mwTestIgnore, mwTester, addons;
/**
* Add bogus to url to prevent IE crazy caching
* @return {String} Such as 'data/foo.js?131031765087663960'
*/
QUnit.fixurl = function ( value ) {
- return value + (/\?/.test( value ) ? '&' : '?')
+ return value + ( /\?/.test( value ) ? '&' : '?' )
+ String( new Date().getTime() )
+ String( parseInt( Math.random() * 100000, 10 ) );
};
sinon.config = {
injectIntoThis: true,
injectInto: null,
- properties: ['spy', 'stub', 'mock', 'sandbox'],
+ properties: [ 'spy', 'stub', 'mock', 'sandbox' ],
// Don't fake timers by default
useFakeTimers: false,
useFakeServer: false
},
teardown: function () {
- var timers, active;
+ var timers, pending, $activeLen;
localEnv.teardown.call( this );
$.each( $.timers, function ( i, timer ) {
var node = timer.elem;
mw.log.warn( 'Unfinished animation #' + i + ' in ' + timer.queue + ' queue on ' +
- mw.html.element( node.nodeName.toLowerCase(), $(node).getAttrs() )
+ mw.html.element( node.nodeName.toLowerCase(), $( node ).getAttrs() )
);
} );
// Force animations to stop to give the next test a clean start
}
// 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 + ')' );
}
}
};
function getDomStructure( node ) {
var $node, children, processedChildren, i, len, el;
$node = $( node );
- if ( node.nodeType === ELEMENT_NODE ) {
+ if ( node.nodeType === Node.ELEMENT_NODE ) {
children = $node.contents();
processedChildren = [];
for ( i = 0, len = children.length; i < len; i++ ) {
- el = children[i];
- if ( el.nodeType === ELEMENT_NODE || el.nodeType === TEXT_NODE ) {
+ el = children[ i ];
+ if ( el.nodeType === Node.ELEMENT_NODE || el.nodeType === Node.TEXT_NODE ) {
processedChildren.push( getDomStructure( el ) );
}
}
* @param {string} html HTML markup for one or more nodes.
*/
function getHtmlStructure( html ) {
- var el = $( '<div>' ).append( html )[0];
+ var el = $( '<div>' ).append( html )[ 0 ];
return getDomStructure( el );
}
missing = [];
for ( i = 0, len = modules.length; i < len; i++ ) {
- state = mw.loader.getState( modules[i] );
+ state = mw.loader.getState( modules[ i ] );
if ( state === 'error' ) {
- error.push( modules[i] );
+ error.push( modules[ i ] );
} else if ( state === 'missing' ) {
- missing.push( modules[i] );
+ missing.push( modules[ i ] );
}
}