From 9a3e82f91914a4911efaa16902fddb2a2fe126b0 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 20 Feb 2014 08:06:05 +0100 Subject: [PATCH] QUnit.newMwEnvironment: Disable mw.log#warn while copying mw.config 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 | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index 6930f38fef..ba00ff9a7c 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -1,6 +1,6 @@ /*global CompletenessTest, sinon */ /*jshint evil: true */ -( function ( $, mw, QUnit, undefined ) { +( function ( $, mw, QUnit ) { 'use strict'; var mwTestIgnore, mwTester, @@ -164,14 +164,23 @@ 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 ) { -- 2.20.1