jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/365681 )
Change subject: tests: Simplify Platform test beforeEach/afterEach logic ...................................................................... tests: Simplify Platform test beforeEach/afterEach logic * Remove needless closure in favour of a context property. Aside from reducing complexity, it is also more semantically correct. While the functions are only defined once and thus share the closure and local variable, the 'this' context will be re-bound each test. In a future where tests run in parallel, afterEach should use the value from the context for which it runs after, not whichever test happened to have last sequentially started. * Use a single loop instead of two separate loops. Borrows logic previously used logic of the kvStore test from CentralNotice. Change-Id: I5a783ac9c12d7dedb5774afc8e18842cb15f92f1 --- M tests/init/ve.init.sa.Platform.test.js 1 file changed, 22 insertions(+), 26 deletions(-) Approvals: Esanders: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/init/ve.init.sa.Platform.test.js b/tests/init/ve.init.sa.Platform.test.js index 5865a9a..1fd50e3 100644 --- a/tests/init/ve.init.sa.Platform.test.js +++ b/tests/init/ve.init.sa.Platform.test.js @@ -4,33 +4,29 @@ * @copyright 2011-2017 VisualEditor Team and others; see http://ve.mit-license.org */ -QUnit.module( 've.init.sa.Platform', ( function () { - var dummyPlatform; - return { - beforeEach: function () { - // Ensure that ve.init.platform is not permanently overwritten - // by creating an sa.Platform - dummyPlatform = ve.init.platform; - this.purgeKeys = function () { - var i, keys = []; - for ( i = 0; i < localStorage.length; i++ ) { - keys.push( localStorage.key( i ) ); +QUnit.module( 've.init.sa.Platform', { + beforeEach: function () { + // Ensure that ve.init.platform is not permanently overwritten + // by creating an sa.Platform + this.originalPlatform = ve.init.platform; + this.purgeKeys = function () { + var key, + i = localStorage.length; + // Loop backwards since removal affects the key index + while ( i-- ) { + key = localStorage.key( i ); + if ( key.indexOf( 've-test-' ) === 0 ) { + localStorage.removeItem( key ); } - // Get keys first since key index is live - keys.forEach( function ( key ) { - if ( key.indexOf( 've-test-' ) === 0 ) { - localStorage.removeItem( key ); - } - } ); - }; - this.purgeKeys(); - }, - afterEach: function () { - ve.init.platform = dummyPlatform; - this.purgeKeys(); - } - }; -}() ) ); + } + }; + this.purgeKeys(); + }, + afterEach: function () { + ve.init.platform = this.originalPlatform; + this.purgeKeys(); + } +} ); QUnit.test( 'getUserConfig', function ( assert ) { var platform = new ve.init.sa.Platform(); -- To view, visit https://gerrit.wikimedia.org/r/365681 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5a783ac9c12d7dedb5774afc8e18842cb15f92f1 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Krinkle <[email protected]> Gerrit-Reviewer: DLynch <[email protected]> Gerrit-Reviewer: Esanders <[email protected]> Gerrit-Reviewer: Jforrester <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
