mw.loader: Minor documentation and test improvements
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 28 Jan 2016 22:23:36 +0000 (23:23 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 28 Jan 2016 22:29:16 +0000 (23:29 +0100)
Update outdated mw.loader.implement documentation

* Not all arguments are required.
* Even 'script' is no longer required. Defaults to 'null' in the registry.
  And supported by execute().
* Add a test for implement() with a name only and no resources.

Bug: T112455
Change-Id: I5ebd8542ae1a4b2f14ffaff560b98b4c1c2adb23

resources/src/mediawiki/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js

index b04e01c..b8349d0 100644 (file)
                /**
                 * Get a message object.
                 *
-                * Shorcut for `new mw.Message( mw.messages, key, parameters )`.
+                * Shortcut for `new mw.Message( mw.messages, key, parameters )`.
                 *
                 * @see mw.Message
                 * @param {string} key Key of message to get
                         */
 
                        /**
-                        * Write a message the console's warning channel.
+                        * Write a message to the console's warning channel.
                         * Actions not supported by the browser console are silently ignored.
                         *
                         * @param {...string} msg Messages to output to console
                                $.noop;
 
                        /**
-                        * Write a message the console's error channel.
+                        * Write a message to the console's error channel.
                         *
                         * Most browsers provide a stacktrace by default if the argument
                         * is a caught Error object.
                        /**
                         * A module has entered state 'ready', 'error', or 'missing'. Automatically update
                         * pending jobs and modules that depend upon this module. If the given module failed,
-                        * propagate the 'error' state up the dependency tree. Otherwise, go ahead an execute
+                        * propagate the 'error' state up the dependency tree. Otherwise, go ahead and execute
                         * all jobs/modules now having their dependencies satisfied.
                         *
                         * Jobs that depend on a failed module, will have their error callback ran (if any).
                                                                script( $, $ );
                                                                markModuleReady();
                                                        } else if ( typeof script === 'string' ) {
-                                                               // Site and user modules are legacy scripts that run in the global scope.
+                                                               // Site and user modules are legacy scripts that run in the global scope.
                                                                // This is transported as a string instead of a function to avoid needing
                                                                // to use string manipulation to undo the function wrapper.
                                                                if ( module === 'user' ) {
                        }
 
                        /**
-                        * Adds a dependencies to the queue with optional callbacks to be run
+                        * Adds all dependencies to the queue with optional callbacks to be run
                         * when the dependencies are ready or fail
                         *
                         * @private
                                 * When #load or #using requests one or more modules, the server
                                 * response contain calls to this function.
                                 *
-                                * All arguments are required.
-                                *
                                 * @param {string} module Name of module
-                                * @param {Function|Array} script Function with module code or Array of URLs to
+                                * @param {Function|Array} [script] Function with module code or Array of URLs to
                                 *  be used as the src attribute of a new `<script>` tag.
                                 * @param {Object} [style] Should follow one of the following patterns:
                                 *
        /**
         * Log a message to window.console, if possible.
         *
-        * Useful to force logging of some  errors that are otherwise hard to detect (i.e., this logs
+        * Useful to force logging of some errors that are otherwise hard to detect (i.e., this logs
         * also in production mode). Gets console references in each invocation instead of caching the
         * reference, so that debugging tools loaded later are supported (e.g. Firebug Lite in IE).
         *
                        msg += ( e ? ':' : '.' );
                        console.log( msg );
 
-                       // If we have an exception object, log it to the error channel to trigger a
-                       // proper stacktraces in browsers that support it. No fallback as we have no browsers
-                       // that don't support error(), but do support log().
+                       // If we have an exception object, log it to the error channel to trigger
+                       // proper stacktraces in browsers that support it. No fallback as we have
+                       // no browsers that don't support error(), but do support log().
                        if ( e && console.error ) {
                                console.error( String( e ), e );
                        }
index ed3f2cd..fe5530b 100644 (file)
                } );
        } );
 
+       QUnit.test( 'mw.loader.implement( empty )', 1, function ( assert ) {
+               mw.loader.implement( 'test.empty' );
+               assert.strictEqual( mw.loader.getState( 'test.empty' ), 'ready' );
+       } );
+
        QUnit.test( 'mw.loader with broken indirect dependency', 4, function ( assert ) {
                // don't emit an error event
                this.sandbox.stub( mw, 'track' );