|
|
@@ -12,7 +12,7 @@ class TestError extends Error {}
|
|
|
|
|
|
bender.tools.createSinonSandbox();
|
|
|
|
|
|
-before( function() {
|
|
|
+before( () => {
|
|
|
const Editor = modules.editor;
|
|
|
const Plugin = modules.plugin;
|
|
|
|
|
|
@@ -24,60 +24,60 @@ before( function() {
|
|
|
|
|
|
// Create fake plugins that will be used on tests.
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!A', function() {
|
|
|
+CKEDITOR.define( 'plugin!A', () => {
|
|
|
return PluginA;
|
|
|
} );
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!B', function() {
|
|
|
+CKEDITOR.define( 'plugin!B', () => {
|
|
|
return PluginB;
|
|
|
} );
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!C', [ 'plugin', 'plugin!B' ], function( Plugin ) {
|
|
|
+CKEDITOR.define( 'plugin!C', [ 'plugin', 'plugin!B' ], ( Plugin ) => {
|
|
|
return class extends Plugin {};
|
|
|
} );
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!D', [ 'plugin', 'plugin!A', 'plugin!C' ], function( Plugin ) {
|
|
|
+CKEDITOR.define( 'plugin!D', [ 'plugin', 'plugin!A', 'plugin!C' ], ( Plugin ) => {
|
|
|
return class extends Plugin {};
|
|
|
} );
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!E', [ 'plugin', 'plugin!F' ], function( Plugin ) {
|
|
|
+CKEDITOR.define( 'plugin!E', [ 'plugin', 'plugin!F' ], ( Plugin ) => {
|
|
|
return class extends Plugin {};
|
|
|
} );
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!F', [ 'plugin', 'plugin!E' ], function( Plugin ) {
|
|
|
+CKEDITOR.define( 'plugin!F', [ 'plugin', 'plugin!E' ], ( Plugin ) => {
|
|
|
return class extends Plugin {};
|
|
|
} );
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!G', function() {
|
|
|
+CKEDITOR.define( 'plugin!G', () => {
|
|
|
throw new TestError( 'Some error inside a plugin' );
|
|
|
} );
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!H', [ 'plugin', 'plugin!H/a' ], function( Plugin ) {
|
|
|
+CKEDITOR.define( 'plugin!H', [ 'plugin', 'plugin!H/a' ], ( Plugin ) => {
|
|
|
return class extends Plugin {};
|
|
|
} );
|
|
|
|
|
|
let spies = {};
|
|
|
// Note: This is NOT a plugin.
|
|
|
-CKEDITOR.define( 'plugin!H/a', [ 'plugin!H/a/b' ], function() {
|
|
|
+CKEDITOR.define( 'plugin!H/a', [ 'plugin!H/a/b' ], () => {
|
|
|
return ( spies[ 'plugin!H/a' ] = sinon.spy() );
|
|
|
} );
|
|
|
|
|
|
// Note: This is NOT a plugin.
|
|
|
-CKEDITOR.define( 'plugin!H/a/b', [ 'c' ], function() {
|
|
|
+CKEDITOR.define( 'plugin!H/a/b', [ 'c' ], () => {
|
|
|
return ( spies[ 'plugin!H/a/b' ] = sinon.spy() );
|
|
|
} );
|
|
|
|
|
|
// Note: This is NOT a plugin.
|
|
|
-CKEDITOR.define( 'c', function() {
|
|
|
+CKEDITOR.define( 'c', () => {
|
|
|
return ( spies.c = sinon.spy() );
|
|
|
} );
|
|
|
|
|
|
-CKEDITOR.define( 'plugin!I', [ 'plugin', 'plugin!J' ], function( Plugin ) {
|
|
|
+CKEDITOR.define( 'plugin!I', [ 'plugin', 'plugin!J' ], ( Plugin ) => {
|
|
|
return class extends Plugin {};
|
|
|
} );
|
|
|
|
|
|
// Note: This is NOT a plugin.
|
|
|
-CKEDITOR.define( 'plugin!J', function() {
|
|
|
+CKEDITOR.define( 'plugin!J', () => {
|
|
|
return function() {
|
|
|
return ( spies.jSpy = sinon.spy() );
|
|
|
};
|
|
|
@@ -85,36 +85,36 @@ CKEDITOR.define( 'plugin!J', function() {
|
|
|
|
|
|
/////////////
|
|
|
|
|
|
-describe( 'load', function() {
|
|
|
- it( 'should not fail when trying to load 0 plugins (empty string)', function() {
|
|
|
+describe( 'load', () => {
|
|
|
+ it( 'should not fail when trying to load 0 plugins (empty string)', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
|
|
|
return plugins.load( '' )
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
expect( plugins.length ).to.equal( 0 );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should not fail when trying to load 0 plugins (undefined)', function() {
|
|
|
+ it( 'should not fail when trying to load 0 plugins (undefined)', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
|
|
|
return plugins.load()
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
expect( plugins.length ).to.equal( 0 );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should add collection items for loaded plugins', function() {
|
|
|
+ it( 'should add collection items for loaded plugins', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
|
|
|
return plugins.load( 'A,B' )
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
expect( plugins.length ).to.equal( 2 );
|
|
|
|
|
|
expect( plugins.get( 'A' ) ).to.be.an.instanceof( PluginA );
|
|
|
@@ -122,14 +122,14 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should load dependency plugins', function() {
|
|
|
+ it( 'should load dependency plugins', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
let spy = sinon.spy( plugins, 'add' );
|
|
|
|
|
|
return plugins.load( 'A,C' )
|
|
|
- .then( function( loadedPlugins ) {
|
|
|
+ .then( ( loadedPlugins ) => {
|
|
|
expect( plugins.length ).to.equal( 3 );
|
|
|
|
|
|
expect( getPluginNamesFromSpy( spy ) ).to.deep.equal( [ 'A', 'B', 'C' ], 'order by plugins.add()' );
|
|
|
@@ -137,14 +137,14 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should be ok when dependencies are loaded first', function() {
|
|
|
+ it( 'should be ok when dependencies are loaded first', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
let spy = sinon.spy( plugins, 'add' );
|
|
|
|
|
|
return plugins.load( 'A,B,C' )
|
|
|
- .then( function( loadedPlugins ) {
|
|
|
+ .then( ( loadedPlugins ) => {
|
|
|
expect( plugins.length ).to.equal( 3 );
|
|
|
|
|
|
expect( getPluginNamesFromSpy( spy ) ).to.deep.equal( [ 'A', 'B', 'C' ], 'order by plugins.add()' );
|
|
|
@@ -152,14 +152,14 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should load deep dependency plugins', function() {
|
|
|
+ it( 'should load deep dependency plugins', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
let spy = sinon.spy( plugins, 'add' );
|
|
|
|
|
|
return plugins.load( 'D' )
|
|
|
- .then( function( loadedPlugins ) {
|
|
|
+ .then( ( loadedPlugins ) => {
|
|
|
expect( plugins.length ).to.equal( 4 );
|
|
|
|
|
|
// The order must have dependencies first.
|
|
|
@@ -168,14 +168,14 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should handle cross dependency plugins', function() {
|
|
|
+ it( 'should handle cross dependency plugins', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
let spy = sinon.spy( plugins, 'add' );
|
|
|
|
|
|
return plugins.load( 'A,E' )
|
|
|
- .then( function( loadedPlugins ) {
|
|
|
+ .then( ( loadedPlugins ) => {
|
|
|
expect( plugins.length ).to.equal( 3 );
|
|
|
|
|
|
// The order must have dependencies first.
|
|
|
@@ -184,37 +184,37 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should set the `editor` property on loaded plugins', function() {
|
|
|
+ it( 'should set the `editor` property on loaded plugins', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
|
|
|
return plugins.load( 'A,B' )
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
expect( plugins.get( 'A' ).editor ).to.equal( editor );
|
|
|
expect( plugins.get( 'B' ).editor ).to.equal( editor );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should set the `path` property on loaded plugins', function() {
|
|
|
+ it( 'should set the `path` property on loaded plugins', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
|
|
|
return plugins.load( 'A,B' )
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
expect( plugins.get( 'A' ).path ).to.equal( CKEDITOR.getPluginPath( 'A' ) );
|
|
|
expect( plugins.get( 'B' ).path ).to.equal( CKEDITOR.getPluginPath( 'B' ) );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should set the `deps` property on loaded plugins', function() {
|
|
|
+ it( 'should set the `deps` property on loaded plugins', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
|
|
|
return plugins.load( 'A,D' )
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
expect( plugins.get( 'A' ).deps ).to.deep.equal( [] );
|
|
|
expect( plugins.get( 'B' ).deps ).to.deep.equal( [] );
|
|
|
expect( plugins.get( 'C' ).deps ).to.deep.equal( [ 'B' ] );
|
|
|
@@ -222,7 +222,7 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should reject on invalid plugin names (forward require.js loading error)', function() {
|
|
|
+ it( 'should reject on invalid plugin names (forward require.js loading error)', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
let log = modules.log;
|
|
|
|
|
|
@@ -232,10 +232,10 @@ describe( 'load', function() {
|
|
|
|
|
|
return plugins.load( 'A,BAD,B' )
|
|
|
// Throw here, so if by any chance plugins.load() was resolved correctly catch() will be stil executed.
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
throw new Error( 'Test error: this promise should not be resolved successfully' );
|
|
|
} )
|
|
|
- .catch( function( err ) {
|
|
|
+ .catch( ( err ) => {
|
|
|
expect( err ).to.be.an.instanceof( Error );
|
|
|
// Make sure it's the Require.JS error, not the one thrown above.
|
|
|
expect( err.message ).to.match( /^Script error for:/ );
|
|
|
@@ -245,7 +245,7 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should reject on broken plugins (forward the error thrown in a plugin)', function() {
|
|
|
+ it( 'should reject on broken plugins (forward the error thrown in a plugin)', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
let log = modules.log;
|
|
|
|
|
|
@@ -255,10 +255,10 @@ describe( 'load', function() {
|
|
|
|
|
|
return plugins.load( 'A,G,B' )
|
|
|
// Throw here, so if by any chance plugins.load() was resolved correctly catch() will be stil executed.
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
throw new Error( 'Test error: this promise should not be resolved successfully' );
|
|
|
} )
|
|
|
- .catch( function( err ) {
|
|
|
+ .catch( ( err ) => {
|
|
|
expect( err ).to.be.an.instanceof( TestError );
|
|
|
expect( err ).to.have.property( 'message', 'Some error inside a plugin' );
|
|
|
|
|
|
@@ -267,14 +267,14 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should load `deps` which are not plugins', function() {
|
|
|
+ it( 'should load `deps` which are not plugins', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
expect( spies ).to.be.empty;
|
|
|
|
|
|
return plugins.load( 'H' )
|
|
|
- .then( function() {
|
|
|
+ .then( () => {
|
|
|
expect( plugins.get( 'H' ).deps ).to.deep.equal( [ 'H/a' ] );
|
|
|
|
|
|
// Non–plugin dependencies should be loaded (spy exists)...
|
|
|
@@ -291,7 +291,7 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should load instances of Plugin only', function() {
|
|
|
+ it( 'should load instances of Plugin only', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
|
|
|
@@ -304,7 +304,7 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should cancel loading module which looks like a plugin but is a normal module', function() {
|
|
|
+ it( 'should cancel loading module which looks like a plugin but is a normal module', () => {
|
|
|
const PluginCollection = modules.plugincollection;
|
|
|
let plugins = new PluginCollection( editor );
|
|
|
|
|
|
@@ -320,13 +320,13 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
|
|
|
function getPluginNamesFromSpy( addSpy ) {
|
|
|
- return addSpy.args.map( function( arg ) {
|
|
|
+ return addSpy.args.map( ( arg ) => {
|
|
|
return arg[ 0 ].name;
|
|
|
} );
|
|
|
}
|
|
|
|
|
|
function getPluginNames( plugins ) {
|
|
|
- return plugins.map( function( arg ) {
|
|
|
+ return plugins.map( ( arg ) => {
|
|
|
return arg.name;
|
|
|
} );
|
|
|
}
|