Move test registry hacks into QUnit setup/teardown hooks

Change-Id: I7b56bc7a9a69f64073ab97bdb1911d17b328b8b8
This commit is contained in:
Ed Sanders 2015-05-17 10:37:34 +01:00
parent ee9da3101e
commit b7f92605b2
12 changed files with 57 additions and 27 deletions

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.ce.ContentBranchNode (MW)' );
QUnit.module( 've.ce.ContentBranchNode (MW)', ve.test.utils.mwEnvironment );
/* Tests */

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.ce.Surface (MW)' );
QUnit.module( 've.ce.Surface (MW)', ve.test.utils.mwEnvironment );
/* Tests */

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.MWTransclusionNode' );
QUnit.module( 've.dm.MWTransclusionNode', ve.test.utils.mwEnvironment );
/* Tests */

View file

@ -5,19 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.Converter (MW)', QUnit.newMwEnvironment() );
ve.test.utils.modelRegistrySetup = function () {
ve.dm.modelRegistry.register( ve.dm.MWHeadingNode );
ve.dm.modelRegistry.register( ve.dm.MWPreformattedNode );
ve.dm.modelRegistry.register( ve.dm.MWTableNode );
};
ve.test.utils.modelRegistryTeardown = function () {
ve.dm.modelRegistry.register( ve.dm.HeadingNode );
ve.dm.modelRegistry.register( ve.dm.PreformattedNode );
ve.dm.modelRegistry.register( ve.dm.TableNode );
};
QUnit.module( 've.dm.Converter (MW)', ve.test.utils.mwEnvironment );
QUnit.test( 'getModelFromDom', function ( assert ) {
var msg, caseItem,
@ -25,7 +13,6 @@ QUnit.test( 'getModelFromDom', function ( assert ) {
QUnit.expect( ve.test.utils.countGetModelFromDomTests( cases ) );
ve.test.utils.modelRegistrySetup();
for ( msg in cases ) {
caseItem = ve.copy( cases[msg] );
if ( caseItem.mwConfig ) {
@ -34,7 +21,6 @@ QUnit.test( 'getModelFromDom', function ( assert ) {
ve.test.utils.runGetModelFromDomTest( assert, caseItem, msg );
}
ve.test.utils.modelRegistryTeardown();
} );
QUnit.test( 'getDomFromModel', function ( assert ) {
@ -43,7 +29,6 @@ QUnit.test( 'getDomFromModel', function ( assert ) {
QUnit.expect( 3 * Object.keys( cases ).length );
ve.test.utils.modelRegistrySetup();
for ( msg in cases ) {
caseItem = ve.copy( cases[msg] );
if ( caseItem.mwConfig ) {
@ -52,5 +37,4 @@ QUnit.test( 'getDomFromModel', function ( assert ) {
ve.test.utils.runGetDomFromModelTest( assert, caseItem, msg );
}
ve.test.utils.modelRegistryTeardown();
} );

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.Document (MW)' );
QUnit.module( 've.dm.Document (MW)', ve.test.utils.mwEnvironment );
/* Tests */

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.InternalList (MW)' );
QUnit.module( 've.dm.InternalList (MW)', ve.test.utils.mwEnvironment );
/* Tests */

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.MWImageModel' );
QUnit.module( 've.dm.MWImageModel', ve.test.utils.mwEnvironment );
/* Tests */

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.SurfaceFragment (MW)' );
QUnit.module( 've.dm.SurfaceFragment (MW)', ve.test.utils.mwEnvironment );
/* Tests */

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.Transaction (MW)' );
QUnit.module( 've.dm.Transaction (MW)', ve.test.utils.mwEnvironment );
// FIXME: Duplicates test runner; should be using a data provider
QUnit.test( 'newFromDocumentInsertion with references', function ( assert ) {

View file

@ -6,7 +6,7 @@
*/
/*global mw */
QUnit.module( 've.init.mw.ViewPageTarget' );
QUnit.module( 've.init.mw.ViewPageTarget', ve.test.utils.mwEnvironment );
QUnit.test( 'compatibility', function ( assert ) {
var i, profile, list, matches, compatibility,

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.ui.FormatAction (MW)' );
QUnit.module( 've.ui.FormatAction (MW)', ve.test.utils.mwEnvironment );
/* Tests */

View file

@ -21,3 +21,49 @@ ve.test.utils.createSurfaceFromDocument = function ( doc ) {
target.addSurface( doc );
return target.surface;
};
// Unregister MW override nodes.
// They are temporarily registered in setup/teardown.
ve.dm.modelRegistry.unregister( ve.dm.MWHeadingNode );
ve.dm.modelRegistry.unregister( ve.dm.MWPreformattedNode );
ve.dm.modelRegistry.unregister( ve.dm.MWTableNode );
// Re-register unregistered nodes.
ve.dm.modelRegistry.register( ve.dm.InlineImageNode );
ve.dm.modelRegistry.register( ve.dm.BlockImageNode );
ve.test.utils.mwEnvironment = ( function () {
var overrides = [
ve.dm.MWHeadingNode,
ve.dm.MWPreformattedNode,
ve.dm.MWTableNode
],
overridden = [];
function setupOverrides() {
var i;
for ( i = 0; i < overrides.length; i++ ) {
ve.dm.modelRegistry.register( overrides[i] );
}
for ( i = 0; i < overridden.length; i++ ) {
ve.dm.modelRegistry.unregister( overridden[i] );
}
}
function teardownOverrides() {
var i;
for ( i = 0; i < overrides.length; i++ ) {
ve.dm.modelRegistry.unregister( overrides[i] );
}
for ( i = 0; i < overridden.length; i++ ) {
ve.dm.modelRegistry.register( overridden[i] );
}
}
// On load, teardown overrides so the first core tests run correctly
teardownOverrides();
return QUnit.newMwEnvironment( {
setup: setupOverrides,
teardown: teardownOverrides
} );
} )();