( function ( $, mw, QUnit, undefined ) {
-"use strict";
+/*global CompletenessTest */
+/*jshint evil:true */
+'use strict';
var mwTestIgnore, mwTester, addons;
QUnit.config.testTimeout = 10 * 1000;
// Add a checkbox to QUnit header to toggle MediaWiki ResourceLoader debug mode.
-QUnit.config.urlConfig.push( 'debug' );
+QUnit.config.urlConfig.push( {
+ id: 'debug',
+ label: 'Enable ResourceLoaderDebug',
+ tooltip: 'Enable debug mode in ResourceLoader'
+} );
/**
* Load TestSwarm agent
* CompletenessTest
*/
// Adds toggle checkbox to header
-QUnit.config.urlConfig.push( 'completenesstest' );
+QUnit.config.urlConfig.push( {
+ id: 'completenesstest',
+ label: 'Run CompletenessTest',
+ tooltip: 'Run the completeness test'
+} );
// Initiate when enabled
if ( QUnit.urlParams.completenesstest ) {
mw.config.values = freshConfigCopy( localEnv.config );
mw.messages.values = freshMessagesCopy( localEnv.messages );
- localEnv.setup()
+ localEnv.setup();
},
teardown: function () {
};
}() );
+// $.when stops as soon as one fails, which makes sense in most
+// practical scenarios, but not in a unit test where we really do
+// need to wait until all of them are finished.
+QUnit.whenPromisesComplete = function () {
+ var altPromises = [];
+
+ $.each( arguments, function ( i, arg ) {
+ var alt = $.Deferred();
+ altPromises.push( alt );
+
+ // Whether this one fails or not, forwards it to
+ // the 'done' (resolve) callback of the alternative promise.
+ arg.always( alt.resolve );
+ });
+
+ return $.when.apply( $, altPromises );
+};
+
/**
* Add-on assertion helpers
*/
// Expect boolean true
assertTrue: function ( actual, message ) {
- strictEqual( actual, true, message );
+ QUnit.push( actual === true, actual, true, message );
},
// Expect boolean false
assertFalse: function ( actual, message ) {
- strictEqual( actual, false, message );
+ QUnit.push( actual === false, actual, false, message );
},
// Expect numerical value less than X
// Expect numerical value greater than or equal to X
gtOrEq: function ( actual, expected, message ) {
QUnit.push( actual >= expected, actual, 'greater than or equal to ' + expected, message );
- },
-
- // Backwards compatible with new verions of QUnit
- equals: window.equal,
- same: window.deepEqual
+ }
};
-$.extend( QUnit, addons );
-$.extend( window, addons );
+$.extend( QUnit.assert, addons );
/**
* Small test suite to confirm proper functionality of the utilities and
* initializations in this file.
*/
var envExecCount = 0;
-module( 'mediawiki.tests.qunit.testrunner', QUnit.newMwEnvironment({
+QUnit.module( 'mediawiki.tests.qunit.testrunner', QUnit.newMwEnvironment({
setup: function () {
envExecCount += 1;
this.mwHtmlLive = mw.html;
}
}) );
-test( 'Setup', function () {
- expect( 3 );
-
- equal( mw.html.escape( 'foo' ), 'mocked-1', 'extra setup() callback was ran.' );
- equal( mw.config.get( 'testVar' ), 'foo', 'config object applied' );
- equal( mw.messages.get( 'testMsg' ), 'Foo.', 'messages object applied' );
+QUnit.test( 'Setup', 3, function ( assert ) {
+ assert.equal( mw.html.escape( 'foo' ), 'mocked-1', 'extra setup() callback was ran.' );
+ assert.equal( mw.config.get( 'testVar' ), 'foo', 'config object applied' );
+ assert.equal( mw.messages.get( 'testMsg' ), 'Foo.', 'messages object applied' );
mw.config.set( 'testVar', 'bar' );
mw.messages.set( 'testMsg', 'Bar.' );
});
-test( 'Teardown', function () {
- expect( 3 );
-
- equal( mw.html.escape( 'foo' ), 'mocked-2', 'extra setup() callback was re-ran.' );
- equal( mw.config.get( 'testVar' ), 'foo', 'config object restored and re-applied after test()' );
- equal( mw.messages.get( 'testMsg' ), 'Foo.', 'messages object restored and re-applied after test()' );
+QUnit.test( 'Teardown', 3, function ( assert ) {
+ assert.equal( mw.html.escape( 'foo' ), 'mocked-2', 'extra setup() callback was re-ran.' );
+ assert.equal( mw.config.get( 'testVar' ), 'foo', 'config object restored and re-applied after test()' );
+ assert.equal( mw.messages.get( 'testMsg' ), 'Foo.', 'messages object restored and re-applied after test()' );
});
-module( 'mediawiki.tests.qunit.testrunner-after', QUnit.newMwEnvironment() );
-
-test( 'Teardown', function () {
- expect( 3 );
+QUnit.module( 'mediawiki.tests.qunit.testrunner-after', QUnit.newMwEnvironment() );
- equal( mw.html.escape( '<' ), '<', 'extra teardown() callback was ran.' );
- equal( mw.config.get( 'testVar' ), null, 'config object restored to live in next module()' );
- equal( mw.messages.get( 'testMsg' ), null, 'messages object restored to live in next module()' );
+QUnit.test( 'Teardown', 3, function ( assert ) {
+ assert.equal( mw.html.escape( '<' ), '<', 'extra teardown() callback was ran.' );
+ assert.equal( mw.config.get( 'testVar' ), null, 'config object restored to live in next module()' );
+ assert.equal( mw.messages.get( 'testMsg' ), null, 'messages object restored to live in next module()' );
});
-})( jQuery, mediaWiki, QUnit );
+}( jQuery, mediaWiki, QUnit ) );