Explorar el Código

Removed usage of logger.

Maciej Bukowski hace 6 años
padre
commit
91d3c0bfa9

+ 3 - 2
packages/ckeditor5-core/src/editor/editorui.js

@@ -7,12 +7,13 @@
  * @module core/editor/editorui
  */
 
+/* globals console */
+
 import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
 import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
 
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
-import log from '@ckeditor/ckeditor5-utils/src/log';
 
 /**
  * A class providing the minimal interface that is required to successfully bootstrap any editor UI.
@@ -161,7 +162,7 @@ export default class EditorUI {
 		 * @error editor-ui-deprecated-editable-elements
 		 * @param {module:core/editor/editorui~EditorUI} editorUI Editor UI instance the deprecated property belongs to.
 		 */
-		log.warn(
+		console.warn(
 			'editor-ui-deprecated-editable-elements: ' +
 			'The EditorUI#_editableElements property has been deprecated and will be removed in the near future.',
 			{ editorUI: this } );

+ 9 - 6
packages/ckeditor5-core/src/plugincollection.js

@@ -7,8 +7,9 @@
  * @module core/plugincollection
  */
 
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
-import log from '@ckeditor/ckeditor5-utils/src/log';
+/* globals console */
+
+import CKEditorError, { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
@@ -189,7 +190,7 @@ export default class PluginCollection {
 			const errorMsg = 'plugincollection-plugin-not-found: Some plugins are not available and could not be loaded.';
 
 			// Log the error so it's more visible on the console. Hopefully, for better DX.
-			log.error( errorMsg, { plugins: missingPlugins } );
+			console.error( attachLinkToDocumentation( errorMsg ), { plugins: missingPlugins } );
 
 			return Promise.reject( new CKEditorError( errorMsg, this._editor, { plugins: missingPlugins } ) );
 		}
@@ -231,7 +232,9 @@ export default class PluginCollection {
 					 * @error plugincollection-load
 					 * @param {String} plugin The name of the plugin that could not be loaded.
 					 */
-					log.error( 'plugincollection-load: It was not possible to load the plugin.', { plugin: PluginConstructor } );
+					console.error( attachLinkToDocumentation(
+						'plugincollection-load: It was not possible to load the plugin.'
+					), { plugin: PluginConstructor } );
 
 					throw err;
 				} );
@@ -371,8 +374,8 @@ export default class PluginCollection {
 			 * @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.',
+			console.warn(
+				attachLinkToDocumentation( 'plugincollection-plugin-name-conflict: Two plugins with the same name were loaded.' ),
 				{ pluginName, plugin1: this._plugins.get( pluginName ).constructor, plugin2: PluginConstructor }
 			);
 		} else {

+ 2 - 3
packages/ckeditor5-core/tests/editor/editorui.js

@@ -10,9 +10,8 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
 import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
 
 import testUtils from '../_utils/utils';
-import log from '@ckeditor/ckeditor5-utils/src/log';
 
-/* global document */
+/* global document, console */
 
 describe( 'EditorUI', () => {
 	let editor, ui;
@@ -186,7 +185,7 @@ describe( 'EditorUI', () => {
 	describe( '_editableElements()', () => {
 		it( 'should warn about deprecation', () => {
 			const ui = new EditorUI( editor );
-			const stub = testUtils.sinon.stub( log, 'warn' );
+			const stub = testUtils.sinon.stub( console, 'warn' );
 
 			expect( ui._editableElements ).to.be.instanceOf( Map );
 			sinon.assert.calledWithMatch( stub, 'editor-ui-deprecated-editable-elements' );

+ 35 - 37
packages/ckeditor5-core/tests/plugincollection.js

@@ -3,24 +3,20 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-/* globals setTimeout */
+/* globals setTimeout, console */
 
-import testUtils from '../tests/_utils/utils';
 import Editor from '../src/editor/editor';
 import PluginCollection from '../src/plugincollection';
 import Plugin from '../src/plugin';
-import log from '@ckeditor/ckeditor5-utils/src/log';
 import { expectToThrowCKEditorError, assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 let editor, availablePlugins;
 let PluginA, PluginB, PluginC, PluginD, PluginE, PluginF, PluginG, PluginH, PluginI, PluginJ, PluginK, PluginX, PluginFoo, AnotherPluginFoo;
-class TestError extends Error {}
-class ChildPlugin extends Plugin {}
-class GrandPlugin extends ChildPlugin {}
+class TestError extends Error { }
+class ChildPlugin extends Plugin { }
+class GrandPlugin extends ChildPlugin { }
 
 describe( 'PluginCollection', () => {
-	testUtils.createSinonSandbox();
-
 	before( () => {
 		PluginA = createPlugin( 'A' );
 		PluginB = createPlugin( 'B' );
@@ -73,6 +69,10 @@ describe( 'PluginCollection', () => {
 		PluginFoo.requires = [];
 	} );
 
+	afterEach( () => {
+		sinon.restore();
+	} );
+
 	describe( 'load()', () => {
 		it( 'should not fail when trying to load 0 plugins (empty array)', () => {
 			const plugins = new PluginCollection( editor, availablePlugins );
@@ -240,7 +240,7 @@ describe( 'PluginCollection', () => {
 		} );
 
 		it( 'should reject on broken plugins (forward the error thrown in a plugin)', () => {
-			const logSpy = testUtils.sinon.stub( log, 'error' );
+			const consoleErrorStub = sinon.stub( console, 'error' );
 
 			const plugins = new PluginCollection( editor, availablePlugins );
 
@@ -253,13 +253,13 @@ describe( 'PluginCollection', () => {
 					expect( err ).to.be.an.instanceof( TestError );
 					expect( err ).to.have.property( 'message', 'Some error inside a plugin' );
 
-					sinon.assert.calledOnce( logSpy );
-					expect( logSpy.args[ 0 ][ 0 ] ).to.match( /^plugincollection-load:/ );
+					sinon.assert.calledOnce( consoleErrorStub );
+					expect( consoleErrorStub.args[ 0 ][ 0 ] ).to.match( /^plugincollection-load:/ );
 				} );
 		} );
 
 		it( 'should reject when loading non-existent plugin', () => {
-			const logSpy = testUtils.sinon.stub( log, 'error' );
+			const consoleErrorStub = sinon.stub( console, 'error' );
 
 			const plugins = new PluginCollection( editor, availablePlugins );
 
@@ -271,8 +271,8 @@ describe( 'PluginCollection', () => {
 				.catch( err => {
 					assertCKEditorError( err, /^plugincollection-plugin-not-found/, editor );
 
-					sinon.assert.calledOnce( logSpy );
-					expect( logSpy.args[ 0 ][ 0 ] ).to.match( /^plugincollection-plugin-not-found:/ );
+					sinon.assert.calledOnce( consoleErrorStub );
+					expect( consoleErrorStub.args[ 0 ][ 0 ] ).to.match( /^plugincollection-plugin-not-found:/ );
 				} );
 		} );
 
@@ -325,7 +325,7 @@ describe( 'PluginCollection', () => {
 		} );
 
 		it( 'should load chosen plugins (plugins are names, removePlugins contains an anonymous plugin)', () => {
-			class AnonymousPlugin {}
+			class AnonymousPlugin { }
 
 			const plugins = new PluginCollection( editor, [ AnonymousPlugin ].concat( availablePlugins ) );
 
@@ -339,7 +339,7 @@ describe( 'PluginCollection', () => {
 		} );
 
 		it( 'should reject when loaded plugin requires not allowed plugins', () => {
-			const logSpy = testUtils.sinon.stub( log, 'error' );
+			const consoleErrorStub = sinon.stub( console, 'error' );
 			const plugins = new PluginCollection( editor, availablePlugins );
 
 			return plugins.init( [ PluginA, PluginB, PluginC, PluginD ], [ PluginA, PluginB ] )
@@ -350,12 +350,12 @@ describe( 'PluginCollection', () => {
 				.catch( err => {
 					assertCKEditorError( err, /^plugincollection-required/, editor );
 
-					expect( logSpy.calledTwice ).to.equal( true );
+					sinon.assert.calledTwice( consoleErrorStub );
 				} );
 		} );
 
 		it( 'logs if tries to load more than one plugin with the same name', () => {
-			const logSpy = testUtils.sinon.stub( log, 'warn' );
+			const consoleWarnStub = sinon.stub( console, 'warn' );
 			const plugins = new PluginCollection( editor );
 
 			return plugins.init( [ PluginFoo, AnotherPluginFoo ] )
@@ -366,10 +366,10 @@ describe( 'PluginCollection', () => {
 					expect( plugins.get( PluginFoo ) ).to.be.an.instanceof( PluginFoo );
 					expect( plugins.get( AnotherPluginFoo ) ).to.be.an.instanceof( AnotherPluginFoo );
 
-					expect( logSpy.calledOnce ).to.equal( true );
-					expect( logSpy.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
+					sinon.assert.calledOnce( consoleWarnStub );
+					expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
 
-					const warnData = logSpy.firstCall.args[ 1 ];
+					const warnData = consoleWarnStub.firstCall.args[ 1 ];
 					expect( warnData.pluginName ).to.equal( 'Foo' );
 					expect( warnData.plugin1 ).to.equal( PluginFoo );
 					expect( warnData.plugin2 ).to.equal( AnotherPluginFoo );
@@ -379,7 +379,7 @@ describe( 'PluginCollection', () => {
 		it( 'logs if tries to load more than one plugin with the same name (plugin requires plugin with the same name)', () => {
 			PluginFoo.requires = [ AnotherPluginFoo ];
 
-			const logSpy = testUtils.sinon.stub( log, 'warn' );
+			const consoleWarnStub = sinon.stub( console, 'warn' );
 			const plugins = new PluginCollection( editor );
 
 			return plugins.init( [ PluginFoo ] )
@@ -390,17 +390,16 @@ describe( 'PluginCollection', () => {
 					expect( plugins.get( AnotherPluginFoo ) ).to.be.an.instanceof( AnotherPluginFoo );
 					expect( plugins.get( PluginFoo ) ).to.be.an.instanceof( PluginFoo );
 
-					expect( logSpy.calledOnce ).to.equal( true );
-					expect( logSpy.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
+					expect( consoleWarnStub.calledOnce ).to.equal( true );
+					expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
 				} );
 		} );
 
-		it(
-			'logs if tries to load more than one plugin with the same name (plugin with the same name is built-in the PluginCollection)',
+		it( 'logs if tries to load more than one plugin with the same name (plugin with the same name is built-in the PluginCollection)',
 			() => {
 				availablePlugins = [ PluginFoo ];
 
-				const logSpy = testUtils.sinon.stub( log, 'warn' );
+				const consoleWarnStub = sinon.stub( console, 'warn' );
 				const plugins = new PluginCollection( editor, availablePlugins );
 
 				return plugins.init( [ 'Foo', AnotherPluginFoo ] )
@@ -411,16 +410,15 @@ describe( 'PluginCollection', () => {
 						expect( plugins.get( PluginFoo ) ).to.be.an.instanceof( PluginFoo );
 						expect( plugins.get( AnotherPluginFoo ) ).to.be.an.instanceof( AnotherPluginFoo );
 
-						expect( logSpy.calledOnce ).to.equal( true );
-						expect( logSpy.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
+						expect( consoleWarnStub.calledOnce ).to.equal( true );
+						expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^plugincollection-plugin-name-conflict:/ );
 					} );
-			}
-		);
+			} );
 	} );
 
 	describe( 'get()', () => {
 		it( 'retrieves plugin by its constructor', () => {
-			class SomePlugin extends Plugin {}
+			class SomePlugin extends Plugin { }
 
 			availablePlugins.push( SomePlugin );
 
@@ -433,7 +431,7 @@ describe( 'PluginCollection', () => {
 		} );
 
 		it( 'retrieves plugin by its name and constructor', () => {
-			class SomePlugin extends Plugin {}
+			class SomePlugin extends Plugin { }
 			SomePlugin.pluginName = 'foo/bar';
 
 			availablePlugins.push( SomePlugin );
@@ -458,7 +456,7 @@ describe( 'PluginCollection', () => {
 		} );
 
 		it( 'throws if plugin cannot be retrieved by class', () => {
-			class SomePlugin extends Plugin {}
+			class SomePlugin extends Plugin { }
 			SomePlugin.pluginName = 'foo';
 
 			const plugins = new PluginCollection( editor, availablePlugins );
@@ -470,7 +468,7 @@ describe( 'PluginCollection', () => {
 		} );
 
 		it( 'throws if plugin cannot be retrieved by class (class name in error)', () => {
-			class SomePlugin extends Plugin {}
+			class SomePlugin extends Plugin { }
 
 			const plugins = new PluginCollection( editor, availablePlugins );
 
@@ -597,8 +595,8 @@ describe( 'PluginCollection', () => {
 		} );
 
 		it( 'returns only plugins by constructors', () => {
-			class SomePlugin1 extends Plugin {}
-			class SomePlugin2 extends Plugin {}
+			class SomePlugin1 extends Plugin { }
+			class SomePlugin2 extends Plugin { }
 			SomePlugin2.pluginName = 'foo/bar';
 
 			availablePlugins.push( SomePlugin1 );