8
0
Pārlūkot izejas kodu

Added deep copying editor config.

Maciej Bukowski 6 gadi atpakaļ
vecāks
revīzija
5440245101

+ 5 - 2
packages/ckeditor5-watchdog/src/watchdog.js

@@ -11,7 +11,7 @@
 
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
-import { throttle } from 'lodash-es';
+import { throttle, cloneDeepWith, isElement } from 'lodash-es';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import areConnectedThroughProperties from '@ckeditor/ckeditor5-utils/src/areconnectedthroughproperties';
 
@@ -248,7 +248,10 @@ export default class Watchdog {
 		}
 
 		this._elementOrData = elementOrData;
-		this._config = config;
+
+		this._config = cloneDeepWith( config, function leaveDOMReferences( value ) {
+			return isElement( value ) ? value : undefined;
+		} );
 
 		return Promise.resolve()
 			.then( () => this._creator( elementOrData, config ) )

+ 0 - 2
packages/ckeditor5-watchdog/tests/manual/watchdog.html

@@ -1,5 +1,3 @@
-<button id="error-1">Simulate a 1st editor crash</button>
-<button id="error-2">Simulate a 2nd editor crash</button>
 <button id="random-error">Simulate a random `Error`</button>
 
 <button id="restart">Restart both editors</button>

+ 22 - 12
packages/ckeditor5-watchdog/tests/manual/watchdog.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-/* globals document, console */
+/* globals document, console, window */
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
@@ -14,13 +14,29 @@ const firstEditorElement = document.getElementById( 'editor-1' );
 const secondEditorElement = document.getElementById( 'editor-2' );
 
 const restartButton = document.getElementById( 'restart' );
-const firstEditorErrorButton = document.getElementById( 'error-1' );
-const secondEditorErrorButton = document.getElementById( 'error-2' );
 const randomErrorButton = document.getElementById( 'random-error' );
 
+class TypingError {
+	constructor( editor ) {
+		this.editor = editor;
+	}
+
+	init() {
+		const inputCommand = this.editor.commands.get( 'input' );
+
+		inputCommand.on( 'execute', ( evt, data ) => {
+			const commandArgs = data[ 0 ];
+
+			if ( commandArgs.text === '1' ) {
+				throw new CKEditorError( 'Fake error - input command executed with value `1`', this );
+			}
+		} );
+	}
+}
+
 const editorConfig = {
 	plugins: [
-		ArticlePluginSet,
+		ArticlePluginSet, TypingError
 	],
 	toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote',
 		'insertTable', 'mediaEmbed', 'undo', 'redo' ],
@@ -36,13 +52,10 @@ const editorConfig = {
 // Watchdog 1
 
 const watchdog1 = Watchdog.for( ClassicEditor );
+window.watchdog1 = watchdog1;
 
 watchdog1.create( firstEditorElement, editorConfig ).then( () => {
 	console.log( 'First editor created.' );
-
-	firstEditorErrorButton.addEventListener( 'click', () => {
-		throw new CKEditorError( 'Crash on the first editor model document', watchdog1.editor.model.document );
-	} );
 } );
 
 watchdog1.on( 'error', () => {
@@ -56,13 +69,10 @@ watchdog1.on( 'restart', () => {
 // Watchdog 2
 
 const watchdog2 = Watchdog.for( ClassicEditor );
+window.watchdog2 = watchdog2;
 
 watchdog2.create( secondEditorElement, editorConfig ).then( () => {
 	console.log( 'Second editor created.' );
-
-	secondEditorErrorButton.addEventListener( 'click', () => {
-		throw new CKEditorError( 'Crash on the second editor model document', watchdog2.editor.model.document );
-	} );
 } );
 
 watchdog2.on( 'error', () => {

+ 4 - 4
packages/ckeditor5-watchdog/tests/manual/watchdog.md

@@ -1,9 +1,9 @@
-1. Simulate the 1st editor crash with the button. Only the first editor should be restarted. The error should be logged in the console.
+1. Type `1` in the first editor. Only the first editor should crash and be restarted. The error should be logged in the console.
 
-1. Simulate the 2nd editor crash with the button. Only the second editor should be restarted. The error should be logged in the console.
+1. Type `1` in the second editor. Only the second editor should crash and be restarted. The error should be logged in the console.
 
-1. Simulate a random `Error` No editor should be restarted.
+1. Click `Simulate a random error` No editor should be restarted.
 
-1. Run `Simulate the 1st editor crash` 3 more times. The last time and in the future this editor won't be restarted.
+1. Refresh page and type `1` in the first editor 4 times. The last time the editor should not be restarted.
 
 1. Run `restart both editor`. Both editors should be restarted.