-/*global CompletenessTest */
+/*global CompletenessTest, sinon */
/*jshint evil: true */
-( function ( $, mw, QUnit, undefined ) {
+( function ( $, mw, QUnit ) {
'use strict';
var mwTestIgnore, mwTester,
tooltip: 'Run the completeness test'
} );
+ /**
+ * SinonJS
+ *
+ * Glue code for nicer integration with QUnit setup/teardown
+ * Inspired by http://sinonjs.org/releases/sinon-qunit-1.0.0.js
+ * Fixes:
+ * - Work properly with asynchronous QUnit by using module setup/teardown
+ * instead of synchronously wrapping QUnit.test.
+ */
+ sinon.assert.fail = function ( msg ) {
+ QUnit.assert.ok( false, msg );
+ };
+ sinon.assert.pass = function ( msg ) {
+ QUnit.assert.ok( true, msg );
+ };
+ sinon.config = {
+ injectIntoThis: true,
+ injectInto: null,
+ properties: ['spy', 'stub', 'mock', 'sandbox'],
+ // Don't fake timers by default
+ useFakeTimers: false,
+ useFakeServer: false
+ };
+ ( function () {
+ var orgModule = QUnit.module;
+
+ QUnit.module = function ( name, localEnv ) {
+ localEnv = localEnv || {};
+ orgModule( name, {
+ setup: function () {
+ var config = sinon.getConfig( sinon.config );
+ config.injectInto = this;
+ sinon.sandbox.create( config );
+
+ if ( localEnv.setup ) {
+ localEnv.setup.call( this );
+ }
+ },
+ teardown: function () {
+ this.sandbox.verifyAndRestore();
+
+ if ( localEnv.teardown ) {
+ localEnv.teardown.call( this );
+ }
+ }
+ } );
+ };
+ }() );
+
// Initiate when enabled
if ( QUnit.urlParams.completenesstest ) {
liveMessages = mw.messages.values;
function freshConfigCopy( custom ) {
+ var copy, warn;
// Tests should mock all factors that directly influence the tested code.
- // For backwards compatibility though we set mw.config to a copy of the live config
- // and extend it with the (optionally) given custom settings for this test
- // (instead of starting blank with only the given custmo settings).
- // This is a shallow copy, so we don't end up with settings taking an array value
- // extended with the custom settings - setting a config property means you override it,
- // not extend it.
- return $.extend( {}, liveConfig, custom );
+ // For backwards compatibility though we set mw.config to a fresh copy of the live
+ // config. This way any modifications made to mw.config during the test will not
+ // affect other tests, nor the global scope outside the test runner.
+ // This is a shallow copy, since overriding an array or object value via "custom"
+ // should replace it. Setting a config property means you override it, not extend it.
+ // NOTE: It is important that we temporarily disable mw.log#warn as extend() will
+ // trigger MWDeprecationWarning for each of the deprecated properties.
+ warn = mw.log.warn;
+ mw.log.warn = $.noop;
+
+ copy = $.extend( {}, liveConfig, custom );
+
+ mw.log.warn = warn;
+
+ return copy;
}
function freshMessagesCopy( custom ) {
mw.config.values = freshConfigCopy( localEnv.config );
mw.messages.values = freshMessagesCopy( localEnv.messages );
- localEnv.setup();
+ localEnv.setup.call( this );
},
teardown: function () {
log( 'MwEnvironment> TEARDOWN for "' + QUnit.config.current.module
+ ': ' + QUnit.config.current.testName + '"' );
- localEnv.teardown();
+ localEnv.teardown.call( this );
// Farewell, mock environment!
mw.config.values = liveConfig;
* initializations defined above in this file.
*/
envExecCount = 0;
- QUnit.module( 'mediawiki.tests.qunit.testrunner', QUnit.newMwEnvironment( {
+ QUnit.module( 'test.mediawiki.qunit.testrunner', QUnit.newMwEnvironment( {
setup: function () {
envExecCount += 1;
this.mwHtmlLive = mw.html;
} );
- QUnit.module( 'mediawiki.tests.qunit.testrunner-after', QUnit.newMwEnvironment() );
+ QUnit.module( 'test.mediawiki.qunit.testrunner-after', QUnit.newMwEnvironment() );
QUnit.test( 'Teardown', 3, function ( assert ) {
assert.equal( mw.html.escape( '<' ), '<', 'extra teardown() callback was ran.' );