From: Timo Tijhof Date: Mon, 7 Apr 2014 18:43:19 +0000 (-0700) Subject: qunit: Implement suppressWarnings/restoreWarnings X-Git-Tag: 1.31.0-rc.0~16327^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=4c66b7fb91a1edd89001b5acc816430fe07773ef;p=lhc%2Fweb%2Fwiklou.git qunit: Implement suppressWarnings/restoreWarnings There are various tests triggering deprecation warnings because they are testing deprecated functionality, on purpose. Surpress these so that the logs aren't filled with false positives in Jenkins. Change-Id: I4bb546781a0c89999b2e5df7715abf492a44856d --- diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index 73ae0e656a..7dff354837 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -158,27 +158,36 @@ * */ QUnit.newMwEnvironment = ( function () { - var log, liveConfig, liveMessages; + var warn, log, liveConfig, liveMessages; liveConfig = mw.config.values; liveMessages = mw.messages.values; + function suppressWarnings() { + warn = mw.log.warn; + mw.log.warn = $.noop; + } + + function restoreWarnings() { + if ( warn !== undefined ) { + mw.log.warn = warn; + warn = undefined; + } + } + function freshConfigCopy( custom ) { - var copy, warn; + var copy; // Tests should mock all factors that directly influence the tested code. // 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; - + // NOTE: It is important that we suppress warnings because extend() will also access + // deprecated properties and trigger deprecation warnings from mw.log#deprecate. + suppressWarnings(); copy = $.extend( {}, liveConfig, custom ); - - mw.log.warn = warn; + restoreWarnings(); return copy; } @@ -207,6 +216,8 @@ // Greetings, mock environment! mw.config.values = freshConfigCopy( localEnv.config ); mw.messages.values = freshMessagesCopy( localEnv.messages ); + this.suppressWarnings = suppressWarnings; + this.restoreWarnings = restoreWarnings; localEnv.setup.call( this ); }, @@ -220,6 +231,10 @@ // Farewell, mock environment! mw.config.values = liveConfig; mw.messages.values = liveMessages; + + // As a convenience feature, automatically restore warnings if they're + // still suppressed by the end of the test. + restoreWarnings(); } }; }; diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js index e5066e0daf..dab35f60d0 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js @@ -51,6 +51,8 @@ var api = new mw.Api(); + this.suppressWarnings(); + api.get( {}, function () { assert.ok( true, 'Function argument treated as success callback.' ); } ); @@ -67,6 +69,8 @@ } } ); + this.restoreWarnings(); + this.server.respondWith( /action=query/, function ( request ) { request.respond( 200, { 'Content-Type': 'application/json' }, '[]' ); } ); diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js index 41b0cb7035..e1fcb6a9f5 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js @@ -33,10 +33,13 @@ QUnit.test( 'Initial check', 8, function ( assert ) { assert.ok( window.jQuery, 'jQuery defined' ); - assert.ok( window.$, '$j defined' ); - assert.ok( window.$j, '$j defined' ); + assert.ok( window.$, '$ defined' ); assert.strictEqual( window.$, window.jQuery, '$ alias to jQuery' ); + + this.suppressWarnings(); + assert.ok( window.$j, '$j defined' ); assert.strictEqual( window.$j, window.jQuery, '$j alias to jQuery' ); + this.restoreWarnings(); assert.ok( window.mediaWiki, 'mediaWiki defined' ); assert.ok( window.mw, 'mw defined' );