Test: Assert that modules loaded correctly.
authorTimo Tijhof <ttijhof@wikimedia.org>
Wed, 3 Apr 2013 19:17:08 +0000 (21:17 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Wed, 3 Apr 2013 21:46:11 +0000 (23:46 +0200)
Since mw.loader catches any uncaught exceptions that modules
throw at run time, it is hard for QUnit and/or the browser
(e.g. PhantomJS) to know about a failure because there is
no assert failure and no uncaught exception (window.onerror).

VisualEditor's init module, for example, has a problem (bug 45175)
that sometimes causes an error, causing none of the tests to run,
yet the QUnit run would finish successful with simply none of the
VE tests included in the results.

Bug: 44299
Change-Id: Ib6e2b8d1be3e38fd9f1b948407c62da550fce0b4

tests/qunit/data/testrunner.js

index a6f729b..3f3c899 100644 (file)
                assert.equal( mw.messages.get( 'testMsg' ), 'Foo.', 'messages object restored and re-applied after test()' );
        } );
 
+       QUnit.test( 'Loader status', 2, function ( assert ) {
+               var i, len, state,
+                       modules = mw.loader.getModuleNames(),
+                       error = [],
+                       missing = [];
+
+               for ( i = 0, len = modules.length; i < len; i++ ) {
+                       state = mw.loader.getState( modules[i] );
+                       if ( state === 'error' ) {
+                               error.push( modules[i] );
+                       } else if ( state === 'missing' ) {
+                               missing.push( modules[i] );
+                       }
+               }
+
+               assert.deepEqual( error, [], 'Modules in error state' );
+               assert.deepEqual( missing, [], 'Modules in missing state' );
+       } );
+
        QUnit.test( 'htmlEqual', 8, 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>',