QUnit.newMwEnvironment: Disable mw.log#warn while copying mw.config
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 20 Feb 2014 07:06:05 +0000 (08:06 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 20 Feb 2014 07:38:42 +0000 (08:38 +0100)
As of 89a8fe4, mw.log#warn is available in non-debug mode so that
e.g. MWDeprecationWarning are emitted whenever such property is
accessed.

Due to the way QUnit.newMwEnvironment makes a copy of the live
config for the duration of a test run (using $.extend) this
causes all the accessors to be triggered.

As a result the qunit log is inflated to 100s of MWDeprecationWarning
entries before every single test:

 http://integration.wikimedia.org/ci/job/mediawiki-core-qunit/16525/console

Using Object.create (with polyfill) doesn't work since mw.Map#get
only resolves own properties.

Change-Id: I7285c56bd1ae7ef2efae15ee0427eeb77bc240ac

tests/qunit/data/testrunner.js

index 6930f38..ba00ff9 100644 (file)
@@ -1,6 +1,6 @@
 /*global CompletenessTest, sinon */
 /*jshint evil: true */
-( function ( $, mw, QUnit, undefined ) {
+( function ( $, mw, QUnit ) {
        'use strict';
 
        var mwTestIgnore, mwTester,
                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 ) {