qunit/testrunner: Log relevant node in unfinished animations and reset
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 20 Nov 2014 17:54:05 +0000 (17:54 +0000)
committerKrinkle <krinklemail@gmail.com>
Wed, 26 Nov 2014 06:27:11 +0000 (06:27 +0000)
Having unfinished animations affect other test can be a problem,
but when it does happen, having just a number isn't helpful in
trying to pinpoint the cause.

Logging a description of the element should make this relatively
straight forward.

Also reset the animations after the test so that the next test has a
clean start (instead of the current situation where every subsequent
test, until the animation finishes, also reports it as a failure).

Example:

 Unfinished animation #0 in fx queue on <div class="mw-notification
  mw-notification-tag-legacy" style="opacity: 0; "/>

Change-Id: I41058c4cba3383e3ad1456990ccf8dae4ca64951

tests/qunit/data/testrunner.js

index 96a88f0..b800bc2 100644 (file)
                                },
 
                                teardown: function () {
+                                       var timers;
                                        log( 'MwEnvironment> TEARDOWN for "' + QUnit.config.current.module
                                                + ': ' + QUnit.config.current.testName + '"' );
 
                                        // Check for incomplete animations/requests/etc and throw
                                        // error if there are any.
                                        if ( $.timers && $.timers.length !== 0 ) {
-                                               // Test may need to use fake timers, wait for animations or
-                                               // call $.fx.stop().
-                                               throw new Error( 'Unfinished animations: ' + $.timers.length );
+                                               timers = $.timers.length;
+                                               // Tests shoulld use fake timers or wait for animations to complete
+                                               $.each( $.timers, function ( i, timer ) {
+                                                       var node = timer.elem;
+                                                       mw.log.warn( 'Unfinished animation #' + i + ' in ' + timer.queue + ' queue on ' +
+                                                               mw.html.element( node.nodeName.toLowerCase(), $(node).getAttrs() )
+                                                       );
+                                               } );
+                                               // Force animations to stop to give the next test a clean start
+                                               $.fx.stop();
+
+                                               throw new Error( 'Unfinished animations: ' + timers );
                                        }
                                        if ( $.active !== undefined && $.active !== 0 ) {
                                                // Test may need to use fake XHR, wait for requests or