Browse Source

Initial adjustments for porting tests to ES6 modules.

Piotrek Koszuliński 10 years ago
parent
commit
0138aec9b8

+ 0 - 94
packages/ckeditor5-ui/tests/_tools/tools.js

@@ -1,94 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-( () => {
-	bender.tools.core = {
-		/**
-		 * Defines CKEditor plugin which is a mock of an editor creator.
-		 *
-		 * If `proto` is not set or it does not define `create()` and `destroy()` methods,
-		 * then they will be set to Sinon spies. Therefore the shortest usage is:
-		 *
-		 *		bender.tools.defineEditorCreatorMock( 'test1' );
-		 *
-		 * The mocked creator is available under:
-		 *
-		 *		editor.plugins.get( 'creator-thename' );
-		 *
-		 * @param {String} creatorName Name of the creator.
-		 * @param {Object} [proto] Prototype of the creator. Properties from the proto param will
-		 * be copied to the prototype of the creator.
-		 */
-		defineEditorCreatorMock( creatorName, proto ) {
-			bender.amd.define( 'creator-' + creatorName, [ 'core/creator' ], ( Creator ) => {
-				class TestCreator extends Creator {}
-
-				if ( proto ) {
-					for ( let propName in proto ) {
-						TestCreator.prototype[ propName ] = proto[ propName ];
-					}
-				}
-
-				if ( !TestCreator.prototype.create ) {
-					TestCreator.prototype.create = sinon.spy().named( creatorName + '-create' );
-				}
-
-				if ( !TestCreator.prototype.destroy ) {
-					TestCreator.prototype.destroy = sinon.spy().named( creatorName + '-destroy' );
-				}
-
-				return TestCreator;
-			} );
-		},
-
-		/**
-		 * Returns the number of elements return by the iterator.
-		 *
-		 *		bender.tools.core.getIteratorCount( [ 1, 2, 3, 4, 5 ] ); // 5;
-		 *
-		 * @param {Iterable.<*>} iterator Any iterator.
-		 * @returns {Number} Number of elements returned by that iterator.
-		 */
-		getIteratorCount( iterator ) {
-			let count = 0;
-
-			for ( let _ of iterator ) { // jshint ignore:line
-				count++;
-			}
-
-			return count;
-		}
-	};
-
-	bender.tools.treemodel = {
-		/**
-		 * Returns tree structure as a simplified string. Elements are uppercase and characters are lowercase.
-		 * Start and end of an element is marked the same way, by the element's name (in uppercase).
-		 *
-		 *		let element = new Element( 'div', [], [ 'abc', new Element( 'p', [], 'foo' ), 'xyz' ] );
-		 *		bender.tools.treemodel.getNodesAndText( element ); // abcPfooPxyz
-		 *
-		 * @param {treeModel.Range} range Range to stringify.
-		 * @returns {String} String representing element inner structure.
-		 */
-		getNodesAndText: ( range ) => {
-			let txt = '';
-
-			for ( let step of range ) {
-				let node = step.node;
-
-				if ( node.character ) {
-					txt += node.character.toLowerCase();
-				} else if ( node.name ) {
-					txt += node.name.toUpperCase();
-				}
-			}
-
-			return txt;
-		}
-	};
-} )();

+ 0 - 71
packages/ckeditor5-ui/tests/bender/tools.js

@@ -1,71 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* bender-include: ../_tools/tools.js */
-
-'use strict';
-
-let createFn3 = () => {};
-let destroyFn3 = () => {};
-
-bender.tools.core.defineEditorCreatorMock( 'test1' );
-bender.tools.core.defineEditorCreatorMock( 'test2', {
-	foo: 1,
-	bar: 2
-} );
-bender.tools.core.defineEditorCreatorMock( 'test3', {
-	create: createFn3,
-	destroy: destroyFn3
-} );
-
-const modules = bender.amd.require( 'core/creator', 'creator-test1', 'creator-test2', 'creator-test3' );
-let Creator;
-
-///////////////////
-
-before( () => {
-	Creator = modules[ 'core/creator' ];
-} );
-
-describe( 'bender.tools.core.defineEditorCreatorMock()', () => {
-	it( 'should register all creators', () => {
-		const TestCreator1 = modules[ 'creator-test1' ];
-		const TestCreator2 = modules[ 'creator-test2' ];
-		const TestCreator3 = modules[ 'creator-test3' ];
-
-		expect( TestCreator1.prototype ).to.be.instanceof( Creator );
-		expect( TestCreator2.prototype ).to.be.instanceof( Creator );
-		expect( TestCreator3.prototype ).to.be.instanceof( Creator );
-	} );
-
-	it( 'should copy properties from the second argument', () => {
-		const TestCreator = modules[ 'creator-test2' ];
-
-		expect( TestCreator.prototype ).to.have.property( 'foo', 1 );
-		expect( TestCreator.prototype ).to.have.property( 'bar', 2 );
-	} );
-
-	it( 'should create spies for create() and destroy() if not defined', () => {
-		const TestCreator1 = modules[ 'creator-test1' ];
-		const TestCreator2 = modules[ 'creator-test2' ];
-		const TestCreator3 = modules[ 'creator-test3' ];
-
-		expect( TestCreator1.prototype.create ).to.have.property( 'called', false, 'test1.create' );
-		expect( TestCreator1.prototype.destroy ).to.have.property( 'called', false, 'test1.destroy' );
-		expect( TestCreator2.prototype.create ).to.have.property( 'called', false, 'test2.create' );
-		expect( TestCreator2.prototype.destroy ).to.have.property( 'called', false, 'test2.destroy' );
-
-		// Not spies:
-		expect( TestCreator3.prototype ).to.have.property( 'create', createFn3 );
-		expect( TestCreator3.prototype ).to.have.property( 'destroy', destroyFn3 );
-	} );
-} );
-
-describe( 'bender.tools.core.getIteratorCount()', () => {
-	it( 'should returns number of editable items ', () => {
-		const count = bender.tools.core.getIteratorCount( [ 1, 2, 3, 4, 5 ] );
-		expect( count ).to.equal( 5 );
-	} );
-} );

+ 9 - 14
packages/ckeditor5-ui/tests/collection.js

@@ -5,9 +5,12 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'core/collection', 'core/ckeditorerror', 'core/utils' );
+import testUtils from '/tests/_utils/utils.js';
+import Collection from '/ckeditor5/core/collection.js';
+import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
+import utils from '/ckeditor5/core/utils.js';
 
-bender.tools.createSinonSandbox();
+testUtils.createSinonSandbox();
 
 function getItem( id, idProperty ) {
 	idProperty = idProperty || 'id';
@@ -18,14 +21,6 @@ function getItem( id, idProperty ) {
 }
 
 describe( 'Collection', () => {
-	let Collection, CKEditorError, utils;
-
-	before( () => {
-		Collection = modules[ 'core/collection' ];
-		CKEditorError = modules[ 'core/ckeditorerror' ];
-		utils = modules[ 'core/utils' ];
-	} );
-
 	let collection;
 
 	beforeEach( () => {
@@ -150,7 +145,7 @@ describe( 'Collection', () => {
 			() => {
 				let nextUid = 0;
 
-				bender.sinon.stub( utils, 'uid', () => {
+				testUtils.sinon.stub( utils, 'uid', () => {
 					return nextUid++;
 				} );
 
@@ -440,7 +435,7 @@ describe( 'Collection', () => {
 
 	describe( 'map', () => {
 		it( 'uses native map', () => {
-			let spy = bender.sinon.stub( Array.prototype, 'map', () => {
+			let spy = testUtils.sinon.stub( Array.prototype, 'map', () => {
 				return [ 'foo' ];
 			} );
 			let ctx = {};
@@ -458,7 +453,7 @@ describe( 'Collection', () => {
 		it( 'uses native find', () => {
 			let needl = getItem( 'foo' );
 
-			let spy = bender.sinon.stub( Array.prototype, 'find', () => {
+			let spy = testUtils.sinon.stub( Array.prototype, 'find', () => {
 				return needl;
 			} );
 			let ctx = {};
@@ -476,7 +471,7 @@ describe( 'Collection', () => {
 		it( 'uses native filter', () => {
 			let needl = getItem( 'foo' );
 
-			let spy = bender.sinon.stub( Array.prototype, 'filter', () => {
+			let spy = testUtils.sinon.stub( Array.prototype, 'filter', () => {
 				return [ needl ];
 			} );
 			let ctx = {};

+ 2 - 6
packages/ckeditor5-ui/tests/config.js

@@ -5,13 +5,9 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'core/config' );
+import Config from '/ckeditor5/core/config.js';
 
-let Config, config;
-
-before( () => {
-	Config = modules[ 'core/config' ];
-} );
+let config;
 
 beforeEach( () => {
 	config = new Config( {

+ 4 - 8
packages/ckeditor5-ui/tests/emittermixin.js

@@ -5,15 +5,11 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'core/emittermixin', 'core/eventinfo', 'core/lib/lodash/object' );
-let EmitterMixin, EventInfo, utilsObject;
-let emitter, listener;
+import EmitterMixin from '/ckeditor5/core/emittermixin.js';
+import EventInfo from '/ckeditor5/core/eventinfo.js';
+import utilsObject from '/ckeditor5/core/lib/lodash/object.js';
 
-before( () => {
-	EmitterMixin = modules[ 'core/emittermixin' ];
-	EventInfo = modules[ 'core/eventinfo' ];
-	utilsObject = modules[ 'core/lib/lodash/object' ];
-} );
+let emitter, listener;
 
 beforeEach( refreshEmitter );
 

+ 1 - 7
packages/ckeditor5-ui/tests/eventinfo.js

@@ -5,15 +5,9 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'core/eventinfo' );
+import EventInfo from '/ckeditor5/core/eventinfo.js';
 
 describe( 'EventInfo', () => {
-	let EventInfo;
-
-	before( () => {
-		EventInfo = modules[ 'core/eventinfo' ];
-	} );
-
 	it( 'should be created properly', () => {
 		let event = new EventInfo( this, 'test' );
 

+ 1 - 7
packages/ckeditor5-ui/tests/lodash.js

@@ -5,15 +5,9 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'core/lib/lodash/object' );
+import objectUtils from '/ckeditor5/core/lib/lodash/object.js';
 
 describe( 'utils', () => {
-	let objectUtils;
-
-	before( () => {
-		objectUtils = modules[ 'core/lib/lodash/object' ];
-	} );
-
 	describe( 'extend()', () => {
 		// Properties of the subsequent objects should override properties of the preceding objects. This is critical for
 		// CKEditor so we keep this test to ensure that Lo-Dash (or whatever) implements it in the way we need it.

+ 2 - 4
packages/ckeditor5-ui/tests/log.js

@@ -7,13 +7,11 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'core/log' );
-let log;
+import log from '/ckeditor5/core/log.js';
+
 let spy;
 
 beforeEach( () => {
-	log = modules[ 'core/log' ];
-
 	if ( spy ) {
 		spy.restore();
 	}

+ 5 - 10
packages/ckeditor5-ui/tests/model.js

@@ -5,21 +5,16 @@
 
 'use strict';
 
-const modules = bender.amd.require( 'core/model', 'core/eventinfo', 'core/ckeditorerror' );
+import testUtils from '/tests/_utils/utils.js';
+import Model from '/ckeditor5/core/model.js';
+import EventInfo from '/ckeditor5/core/eventinfo.js';
+import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
 
 let Car, car;
 
-bender.tools.createSinonSandbox();
+testUtils.createSinonSandbox();
 
 describe( 'Model', () => {
-	let Model, EventInfo, CKEditorError;
-
-	before( () => {
-		Model = modules[ 'core/model' ];
-		EventInfo = modules[ 'core/eventinfo' ];
-		CKEditorError = modules[ 'core/ckeditorerror' ];
-	} );
-
 	beforeEach( 'Create a test model instance', () => {
 		Car = class extends Model {};