qunit: Make eslint config pass on qunit test files
[lhc/web/wiklou.git] / tests / qunit / data / testrunner.js
index 79f37dc..cef5c15 100644 (file)
@@ -1,8 +1,8 @@
-/*global CompletenessTest, sinon */
+/* global CompletenessTest, sinon */
 ( function ( $, mw, QUnit ) {
        'use strict';
 
-       var mwTestIgnore, mwTester, addons;
+       var mwTestIgnore, addons;
 
        /**
         * Add bogus to url to prevent IE crazy caching
        // killing the test and assuming timeout failure.
        QUnit.config.testTimeout = 60 * 1000;
 
+       // Reduce default animation duration from 400ms to 0ms for unit tests
+       // eslint-disable-next-line no-underscore-dangle
+       $.fx.speeds._default = 0;
+
        // Add a checkbox to QUnit header to toggle MediaWiki ResourceLoader debug mode.
        QUnit.config.urlConfig.push( {
                id: 'debug',
                        return false;
                };
 
-               mwTester = new CompletenessTest( mw, mwTestIgnore );
+               // eslint-disable-next-line no-new
+               new CompletenessTest( mw, mwTestIgnore );
        }
 
        /**
         */
        QUnit.newMwEnvironment = ( function () {
                var warn, error, liveConfig, liveMessages,
+                       MwMap = mw.config.constructor, // internal use only
                        ajaxRequests = [];
 
-               liveConfig = mw.config.values;
-               liveMessages = mw.messages.values;
+               liveConfig = mw.config;
+               liveMessages = mw.messages;
 
                function suppressWarnings() {
                        warn = mw.log.warn;
                        // NOTE: It is important that we suppress warnings because extend() will also access
                        // deprecated properties and trigger deprecation warnings from mw.log#deprecate.
                        suppressWarnings();
-                       copy = $.extend( {}, liveConfig, custom );
+                       copy = $.extend( {}, liveConfig.get(), custom );
                        restoreWarnings();
 
                        return copy;
                }
 
                function freshMessagesCopy( custom ) {
-                       return $.extend( /*deep=*/true, {}, liveMessages, custom );
+                       return $.extend( /* deep */true, {}, liveMessages.get(), custom );
                }
 
                /**
                                setup: function () {
 
                                        // Greetings, mock environment!
-                                       mw.config.values = freshConfigCopy( localEnv.config );
-                                       mw.messages.values = freshMessagesCopy( localEnv.messages );
+                                       mw.config = new MwMap();
+                                       mw.config.set( freshConfigCopy( localEnv.config ) );
+                                       mw.messages = new MwMap();
+                                       mw.messages.set( freshMessagesCopy( localEnv.messages ) );
+                                       // Update reference to mw.messages
+                                       mw.jqueryMsg.setParserDefaults( {
+                                               messages: mw.messages
+                                       } );
+
                                        this.suppressWarnings = suppressWarnings;
                                        this.restoreWarnings = restoreWarnings;
 
                                        $( document ).off( 'ajaxSend', trackAjax );
 
                                        // Farewell, mock environment!
-                                       mw.config.values = liveConfig;
-                                       mw.messages.values = liveMessages;
+                                       mw.config = liveConfig;
+                                       mw.messages = liveMessages;
+                                       // Restore reference to mw.messages
+                                       mw.jqueryMsg.setParserDefaults( {
+                                               messages: liveMessages
+                                       } );
 
                                        // As a convenience feature, automatically restore warnings if they're
                                        // still suppressed by the end of the test.
                }
        } ) );
 
-       QUnit.test( 'Setup', 3, function ( assert ) {
+       QUnit.test( 'Setup', function ( assert ) {
                assert.equal( mw.html.escape( 'foo' ), 'mocked', '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.messages.set( 'testMsg', 'Bar.' );
        } );
 
-       QUnit.test( 'Teardown', 2, function ( assert ) {
+       QUnit.test( 'Teardown', function ( assert ) {
                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()' );
        } );
 
-       QUnit.test( 'Loader status', 2, function ( assert ) {
+       QUnit.test( 'Loader status', function ( assert ) {
                var i, len, state,
                        modules = mw.loader.getModuleNames(),
                        error = [],
                assert.deepEqual( missing, [], 'Modules in missing state' );
        } );
 
-       QUnit.test( 'htmlEqual', 8, function ( assert ) {
+       QUnit.test( 'htmlEqual', function ( assert ) {
                assert.htmlEqual(
                        '<div><p class="some classes" data-length="10">Child paragraph with <a href="http://example.com">A link</a></p>Regular text<span>A span</span></div>',
                        '<div><p data-length=\'10\'  class=\'some classes\'>Child paragraph with <a href=\'http://example.com\' >A link</a></p>Regular text<span>A span</span></div>',
 
        QUnit.module( 'test.mediawiki.qunit.testrunner-after', QUnit.newMwEnvironment() );
 
-       QUnit.test( 'Teardown', 3, function ( assert ) {
+       QUnit.test( 'Teardown', function ( assert ) {
                assert.equal( mw.html.escape( '<' ), '&lt;', '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()' );