From 5a07acd03ccbb2be92ed6cd1471e2f2a256a08b4 Mon Sep 17 00:00:00 2001 From: Daniel Werner Date: Mon, 18 Feb 2013 18:51:09 +0100 Subject: [PATCH] Fix how QUnit.newMwEnvironment merges live and custom settings 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 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index c89656d569..77db2131e4 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -109,12 +109,14 @@ 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 ) { -- 2.20.1