Browse Source

Fixed the usage of log.warn().

Piotrek Koszuliński 8 years ago
parent
commit
c104f2d5f2

+ 14 - 1
packages/ckeditor5-core/src/plugincollection.js

@@ -238,7 +238,20 @@ export default class PluginCollection {
 		}
 
 		if ( this._plugins.has( pluginName ) ) {
-			log.warn( `Plugin "${ pluginName }" is already loaded. You should not load more than one plugin with the same name.` );
+			/**
+			 * Two plugins with the same {@link module:core/plugin~PluginInterface.pluginName} were loaded.
+			 * This may lead to runtime conflicts between these plugins. This usually means that incorrect
+			 * params were passed to {@link module:core/editor/editor~Editor.create}.
+			 *
+			 * @error plugincollection-plugin-name-conflict
+			 * @param {String} pluginName The duplicated plugin name.
+			 * @param {Function} plugin1 The first plugin constructor.
+			 * @param {Function} plugin2 The second plugin constructor.
+			 */
+			log.warn(
+				'plugincollection-plugin-name-conflict: Two plugins with the same name were loaded.',
+				{ pluginName, plugin1: this._plugins.get( pluginName ).constructor, plugin2: PluginConstructor }
+			);
 		} else {
 			this._plugins.set( pluginName, plugin );
 		}

+ 8 - 9
packages/ckeditor5-core/tests/plugincollection.js

@@ -369,9 +369,12 @@ describe( 'PluginCollection', () => {
 					expect( plugins.get( AnotherPluginFoo ) ).to.be.an.instanceof( AnotherPluginFoo );
 
 					expect( logSpy.calledOnce ).to.equal( true );
-					expect( logSpy.firstCall.args[ 0 ] ).to.equal(
-						'Plugin "Foo" is already loaded. You should not load more than one plugin with the same name.'
-					);
+					expect( logSpy.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
+
+					const warnData = logSpy.firstCall.args[ 1 ];
+					expect( warnData.pluginName ).to.equal( 'Foo' );
+					expect( warnData.plugin1 ).to.equal( PluginFoo );
+					expect( warnData.plugin2 ).to.equal( AnotherPluginFoo );
 				} );
 		} );
 
@@ -390,9 +393,7 @@ describe( 'PluginCollection', () => {
 					expect( plugins.get( PluginFoo ) ).to.be.an.instanceof( PluginFoo );
 
 					expect( logSpy.calledOnce ).to.equal( true );
-					expect( logSpy.firstCall.args[ 0 ] ).to.equal(
-						'Plugin "Foo" is already loaded. You should not load more than one plugin with the same name.'
-					);
+					expect( logSpy.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
 				} );
 		} );
 
@@ -413,9 +414,7 @@ describe( 'PluginCollection', () => {
 						expect( plugins.get( AnotherPluginFoo ) ).to.be.an.instanceof( AnotherPluginFoo );
 
 						expect( logSpy.calledOnce ).to.equal( true );
-						expect( logSpy.firstCall.args[ 0 ] ).to.equal(
-							'Plugin "Foo" is already loaded. You should not load more than one plugin with the same name.'
-						);
+						expect( logSpy.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
 					} );
 			}
 		);