8
0
فهرست منبع

Removed usage of logger.

Maciej Bukowski 6 سال پیش
والد
کامیت
01e83af90a

+ 4 - 3
packages/ckeditor5-image/src/imagestyle/utils.js

@@ -7,12 +7,13 @@
  * @module image/imagestyle/utils
  */
 
-import log from '@ckeditor/ckeditor5-utils/src/log';
+/* globals console */
 
 import fullWidthIcon from '@ckeditor/ckeditor5-core/theme/icons/object-full-width.svg';
 import leftIcon from '@ckeditor/ckeditor5-core/theme/icons/object-left.svg';
 import centerIcon from '@ckeditor/ckeditor5-core/theme/icons/object-center.svg';
 import rightIcon from '@ckeditor/ckeditor5-core/theme/icons/object-right.svg';
+import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
  * Default image styles provided by the plugin that can be referred in the
@@ -115,8 +116,8 @@ function _normalizeStyle( style ) {
 		}
 		// If it's just a name but none of the defaults, warn because probably it's a mistake.
 		else {
-			log.warn(
-				'image-style-not-found: There is no such image style of given name.',
+			console.warn(
+				attachLinkToDocumentation( 'image-style-not-found: There is no such image style of given name.' ),
 				{ name: styleName }
 			);
 

+ 4 - 4
packages/ckeditor5-image/tests/imagestyle/utils.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-import log from '@ckeditor/ckeditor5-utils/src/log';
+/* globals console */
 
 import fullWidthIcon from '@ckeditor/ckeditor5-core/theme/icons/object-full-width.svg';
 import leftIcon from '@ckeditor/ckeditor5-core/theme/icons/object-left.svg';
@@ -100,14 +100,14 @@ describe( 'ImageStyle utils', () => {
 			} );
 
 			it( 'should warn if a #name not found in default styles', () => {
-				testUtils.sinon.stub( log, 'warn' );
+				testUtils.sinon.stub( console, 'warn' );
 
 				expect( normalizeImageStyles( [ 'foo' ] ) ).to.deep.equal( [ {
 					name: 'foo'
 				} ] );
 
-				sinon.assert.calledOnce( log.warn );
-				sinon.assert.calledWithExactly( log.warn,
+				sinon.assert.calledOnce( console.warn );
+				sinon.assert.calledWithExactly( console.warn,
 					sinon.match( /^image-style-not-found/ ),
 					{ name: 'foo' }
 				);

+ 6 - 8
packages/ckeditor5-image/tests/imageupload/imageuploadcommand.js

@@ -3,6 +3,8 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
+/* globals console */
+
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
@@ -15,15 +17,9 @@ import { setData as setModelData, getData as getModelData } from '@ckeditor/cked
 import Image from '../../src/image/imageediting';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 
-import log from '@ckeditor/ckeditor5-utils/src/log';
-
-import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
-
 describe( 'ImageUploadCommand', () => {
 	let editor, command, model, fileRepository;
 
-	testUtils.createSinonSandbox();
-
 	class UploadAdapterPluginMock extends Plugin {
 		init() {
 			fileRepository = this.editor.plugins.get( FileRepository );
@@ -50,6 +46,8 @@ describe( 'ImageUploadCommand', () => {
 	} );
 
 	afterEach( () => {
+		sinon.restore();
+
 		return editor.destroy();
 	} );
 
@@ -185,7 +183,7 @@ describe( 'ImageUploadCommand', () => {
 
 			fileRepository.createUploadAdapter = undefined;
 
-			const logStub = testUtils.sinon.stub( log, 'error' );
+			const consoleErrorStub = sinon.stub( console, 'error' );
 
 			setModelData( model, '<paragraph>fo[]o</paragraph>' );
 
@@ -194,7 +192,7 @@ describe( 'ImageUploadCommand', () => {
 			} ).to.not.throw();
 
 			expect( getModelData( model ) ).to.equal( '<paragraph>fo[]o</paragraph>' );
-			expect( logStub.calledOnce ).to.be.true;
+			sinon.assert.calledOnce( consoleErrorStub );
 		} );
 	} );
 } );

+ 23 - 26
packages/ckeditor5-image/tests/imageupload/imageuploadediting.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-/* globals window, setTimeout, atob, URL, Blob */
+/* globals window, setTimeout, atob, URL, Blob, console */
 
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 
@@ -23,9 +23,7 @@ import { UploadAdapterMock, createNativeFileMock, NativeFileReaderMock } from '@
 import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData, stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 
-import log from '@ckeditor/ckeditor5-utils/src/log';
 import env from '@ckeditor/ckeditor5-utils/src/env';
-import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
 
 describe( 'ImageUploadEditing', () => {
@@ -36,8 +34,6 @@ describe( 'ImageUploadEditing', () => {
 	let adapterMocks = [];
 	let editor, model, view, doc, fileRepository, viewDocument, nativeReaderMock, loader;
 
-	testUtils.createSinonSandbox();
-
 	class UploadAdapterPluginMock extends Plugin {
 		init() {
 			fileRepository = this.editor.plugins.get( FileRepository );
@@ -54,15 +50,15 @@ describe( 'ImageUploadEditing', () => {
 
 	beforeEach( () => {
 		if ( isEdgeEnv ) {
-			testUtils.sinon.stub( window, 'File' ).callsFake( () => {
+			sinon.stub( window, 'File' ).callsFake( () => {
 				return { name: 'file.jpg' };
 			} );
 		}
 
 		// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
-		testUtils.sinon.stub( env, 'isEdge' ).get( () => false );
+		sinon.stub( env, 'isEdge' ).get( () => false );
 
-		testUtils.sinon.stub( window, 'FileReader' ).callsFake( () => {
+		sinon.stub( window, 'FileReader' ).callsFake( () => {
 			nativeReaderMock = new NativeFileReaderMock();
 
 			return nativeReaderMock;
@@ -80,11 +76,12 @@ describe( 'ImageUploadEditing', () => {
 				viewDocument = view.document;
 
 				// Stub `view.scrollToTheSelection` as it will fail on VirtualTestEditor without DOM.
-				testUtils.sinon.stub( view, 'scrollToTheSelection' ).callsFake( () => {} );
+				sinon.stub( view, 'scrollToTheSelection' ).callsFake( () => {} );
 			} );
 	} );
 
 	afterEach( () => {
+		sinon.restore();
 		adapterMocks = [];
 
 		return editor.destroy();
@@ -285,7 +282,7 @@ describe( 'ImageUploadEditing', () => {
 	it( 'should not throw when upload adapter is not set (FileRepository will log an error anyway) when image is pasted', () => {
 		const fileMock = createNativeFileMock();
 		const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
-		const logStub = testUtils.sinon.stub( log, 'error' );
+		const consoleErrorStub = sinon.stub( console, 'error' );
 
 		setModelData( model, '<paragraph>[]foo</paragraph>' );
 
@@ -299,7 +296,7 @@ describe( 'ImageUploadEditing', () => {
 		} ).to.not.throw();
 
 		expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph>' );
-		sinon.assert.calledOnce( logStub );
+		sinon.assert.calledOnce( consoleErrorStub );
 	} );
 
 	// https://github.com/ckeditor/ckeditor5-upload/issues/70
@@ -402,7 +399,7 @@ describe( 'ImageUploadEditing', () => {
 	it( 'should not fire notification on abort', done => {
 		const notification = editor.plugins.get( Notification );
 		const file = createNativeFileMock();
-		const spy = testUtils.sinon.spy();
+		const spy = sinon.spy();
 
 		notification.on( 'show:warning', evt => {
 			spy();
@@ -467,7 +464,7 @@ describe( 'ImageUploadEditing', () => {
 
 	it( 'should remove image in case of upload error', done => {
 		const file = createNativeFileMock();
-		const spy = testUtils.sinon.spy();
+		const spy = sinon.spy();
 		const notification = editor.plugins.get( Notification );
 		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 
@@ -495,7 +492,7 @@ describe( 'ImageUploadEditing', () => {
 		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 		editor.execute( 'imageUpload', { file } );
 
-		const abortSpy = testUtils.sinon.spy( loader, 'abort' );
+		const abortSpy = sinon.spy( loader, 'abort' );
 
 		expect( loader.status ).to.equal( 'reading' );
 
@@ -517,8 +514,8 @@ describe( 'ImageUploadEditing', () => {
 		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 		editor.execute( 'imageUpload', { file } );
 
-		const abortSpy = testUtils.sinon.spy( loader, 'abort' );
-		const loadSpy = testUtils.sinon.spy( loader, 'read' );
+		const abortSpy = sinon.spy( loader, 'abort' );
+		const loadSpy = sinon.spy( loader, 'read' );
 
 		const image = doc.getRoot().getChild( 0 );
 
@@ -589,7 +586,7 @@ describe( 'ImageUploadEditing', () => {
 	} );
 
 	it( 'should prevent from browser redirecting when an image is dropped on another image', () => {
-		const spy = testUtils.sinon.spy();
+		const spy = sinon.spy();
 
 		editor.editing.view.document.fire( 'dragover', {
 			preventDefault: spy
@@ -646,7 +643,7 @@ describe( 'ImageUploadEditing', () => {
 			expectModel( done, getModelData( model ), expected );
 		}, { priority: 'low' } );
 
-		testUtils.sinon.stub( fileRepository, 'createLoader' ).callsFake( () => null );
+		sinon.stub( fileRepository, 'createLoader' ).callsFake( () => null );
 
 		setModelData( model, '<paragraph>[]foo</paragraph>' );
 
@@ -684,7 +681,7 @@ describe( 'ImageUploadEditing', () => {
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
 
 		// Stub `fetch` so it can be rejected.
-		testUtils.sinon.stub( window, 'fetch' ).callsFake( () => {
+		sinon.stub( window, 'fetch' ).callsFake( () => {
 			return new Promise( ( res, rej ) => rej() );
 		} );
 
@@ -728,7 +725,7 @@ describe( 'ImageUploadEditing', () => {
 		// Stub `fetch` in a way that 2 first calls are successful and 3rd fails.
 		let counter = 0;
 		const fetch = window.fetch;
-		testUtils.sinon.stub( window, 'fetch' ).callsFake( src => {
+		sinon.stub( window, 'fetch' ).callsFake( src => {
 			counter++;
 			if ( counter < 3 ) {
 				return fetch( src );
@@ -777,11 +774,11 @@ describe( 'ImageUploadEditing', () => {
 	it( 'should not upload and remove image when `File` constructor is not supported', done => {
 		if ( isEdgeEnv ) {
 			// Since on Edge `File` is already stubbed, restore it to it native form so that exception will be thrown.
-			testUtils.sinon.restore();
+			sinon.restore();
 			// Since all stubs were restored, re-stub `scrollToTheSelection`.
-			testUtils.sinon.stub( editor.editing.view, 'scrollToTheSelection' ).callsFake( () => {} );
+			sinon.stub( editor.editing.view, 'scrollToTheSelection' ).callsFake( () => {} );
 		} else {
-			testUtils.sinon.stub( window, 'File' ).throws( 'Function expected.' );
+			sinon.stub( window, 'File' ).throws( 'Function expected.' );
 		}
 
 		const notification = editor.plugins.get( Notification );
@@ -827,7 +824,7 @@ describe( 'ImageUploadEditing', () => {
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
 
 		// Stub `fetch` to return custom blob without type.
-		testUtils.sinon.stub( window, 'fetch' ).callsFake( () => {
+		sinon.stub( window, 'fetch' ).callsFake( () => {
 			return new Promise( res => res( {
 				blob() {
 					return new Promise( res => res( new Blob( [ 'foo', 'bar' ] ) ) );
@@ -855,7 +852,7 @@ describe( 'ImageUploadEditing', () => {
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
 
 		// Stub `fetch` to return custom blob without type.
-		testUtils.sinon.stub( window, 'fetch' ).callsFake( () => {
+		sinon.stub( window, 'fetch' ).callsFake( () => {
 			return new Promise( res => res( {
 				blob() {
 					return new Promise( res => res( new Blob( [ 'foo', 'bar' ] ) ) );
@@ -898,7 +895,7 @@ describe( 'ImageUploadEditing', () => {
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
 
 		// Stub `fetch` in a way that it always fails.
-		testUtils.sinon.stub( window, 'fetch' ).callsFake( () => Promise.reject() );
+		sinon.stub( window, 'fetch' ).callsFake( () => Promise.reject() );
 
 		viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
 	} );