Fix how QUnit.newMwEnvironment merges live and custom settings
authorDaniel Werner <daniel.werner@wikimedia.de>
Mon, 18 Feb 2013 17:51:09 +0000 (18:51 +0100)
committerTimo Tijhof <ttijhof@wikimedia.org>
Thu, 21 Feb 2013 00:53:34 +0000 (01:53 +0100)
We shouldn't merge a live state's setting value with a custom
value anymore as it has been done since I7d20f0b2f4. Doing this
can produce very unpredictable outcome of tests depending on the
server's state and will prevent from being able to properly
define a test's conditions.

Change-Id: I7ad058a45708244918211658b5d4e07f69abba31

tests/qunit/data/testrunner.js

index c89656d..77db213 100644 (file)
                liveMessages = mw.messages.values;
 
                function freshConfigCopy( custom ) {
-                       // "deep=true" is important here.
-                       // Otherwise we just create a new object with values referring to live config.
-                       // e.g. mw.config.set( 'wgFileExtensions', [] ) would not effect liveConfig,
-                       // but mw.config.get( 'wgFileExtensions' ).push( 'png' ) would as the array
-                       // was passed by reference in $.extend's loop.
-                       return $.extend( /*deep=*/true, {}, liveConfig, custom );
+                       // 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 );
                }
 
                function freshMessagesCopy( custom ) {