Ver Fonte

Merge pull request #17 from ckeditor/t/15

Fixed compatibility issues in tests.
Piotrek Koszuliński há 9 anos atrás
pai
commit
d9d747ff51

+ 17 - 2
packages/ckeditor5-core/tests/_utils-tests/module__amd.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals require, bender, window */
+/* globals bender, window, require:true, define:true */
 
 import testUtils from '/tests/core/_utils/utils.js';
 import moduleTestUtils from '/tests/core/_utils/module.js';
@@ -36,6 +36,10 @@ describe( 'amdTestUtils', () => {
 	describe( 'define()', () => {
 		it( 'defines a module by using global define()', () => {
 			const spy = testUtils.sinon.spy( window, 'define' );
+
+			// Required for Sinon's problems with spies on global objects in Safari.
+			define = window.define;
+
 			const expectedDeps = [ 'exports' ].concat( [ 'bar', 'ckeditor' ].map( getModulePath ) );
 
 			moduleTestUtils.define( 'test1', [ 'bar', 'ckeditor' ], () => {} );
@@ -47,6 +51,10 @@ describe( 'amdTestUtils', () => {
 
 		it( 'maps body args and returned value', () => {
 			const spy = testUtils.sinon.spy( window, 'define' );
+
+			// Required for Sinon's problems with spies on global objects in Safari.
+			define = window.define;
+
 			const bodySpy = sinon.spy( () => 'ret' );
 
 			moduleTestUtils.define( 'test2', [ 'bar', 'ckeditor' ], bodySpy );
@@ -66,6 +74,9 @@ describe( 'amdTestUtils', () => {
 		it( 'works with module name and body', () => {
 			const spy = testUtils.sinon.spy( window, 'define' );
 
+			// Required for Sinon's problems with spies on global objects in Safari.
+			define = window.define;
+
 			moduleTestUtils.define( 'test1', () => {} );
 
 			expect( spy.calledOnce ).to.be.true;
@@ -97,14 +108,18 @@ describe( 'amdTestUtils', () => {
 
 	describe( 'require', () => {
 		it( 'blocks Bender and loads modules through global require()', () => {
-			let requireCb;
+			let requireCb = () => {};
 			const deferCbSpy = sinon.spy();
 
 			testUtils.sinon.stub( bender, 'defer', () => deferCbSpy );
+
 			testUtils.sinon.stub( window, 'require', ( deps, cb ) => {
 				requireCb = cb;
 			} );
 
+			// Required for Sinon's problems with spies on global objects in Safari.
+			require = window.require;
+
 			const modules = moduleTestUtils.require( { foo: 'foo/oof', bar: 'bar' } );
 
 			expect( deferCbSpy.called ).to.be.false;

+ 3 - 3
packages/ckeditor5-core/tests/_utils/module__amd.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals bender, define, require */
+/* globals bender, window */
 
 /**
  * AMD tools related to CKEditor.
@@ -84,7 +84,7 @@ const utils = {
 		// Use the exports object instead of returning from modules in order to handle circular deps.
 		// http://requirejs.org/docs/api.html#circular
 		deps.unshift( 'exports' );
-		define( utils.getModulePath( path ), deps, function( exports ) {
+		window.define( utils.getModulePath( path ), deps, function( exports ) {
 			const loadedDeps = Array.from( arguments ).slice( 1 ).map( ( module ) => module.default );
 
 			exports.default = body.apply( this, loadedDeps );
@@ -116,7 +116,7 @@ const utils = {
 			paths.push( utils.getModulePath( modules[ name ] ) );
 		}
 
-		require( paths, function( ...loaded ) {
+		window.require( paths, function( ...loaded ) {
 			for ( let i = 0; i < names.length; i++ ) {
 				resolved[ names[ i ] ] = loaded[ i ].default;
 			}