Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/124374
Change subject: qunit: Implement suppressWarnings/restoreWarnings
......................................................................
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
---
M tests/qunit/data/testrunner.js
M tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js
M tests/qunit/suites/resources/mediawiki/mediawiki.test.js
3 files changed, 34 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/74/124374/1
diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js
index 73ae0e6..7328500 100644
--- a/tests/qunit/data/testrunner.js
+++ b/tests/qunit/data/testrunner.js
@@ -158,27 +158,37 @@
* </code>
*/
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 +217,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 +232,10 @@
// Farewell, mock environment!
mw.config.values = liveConfig;
mw.messages.values = liveMessages;
+
+ // As a convenienice feature,
automatically restore warnings if they're
+ // still surpressed 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 e5066e0..dab35f6 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 41b0cb7..e1fcb6a 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' );
--
To view, visit https://gerrit.wikimedia.org/r/124374
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4bb546781a0c89999b2e5df7715abf492a44856d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits