瀏覽代碼

Added manual test.

Maciej Bukowski 6 年之前
父節點
當前提交
ef3123a29e

+ 6 - 1
packages/ckeditor5-watchdog/src/watchdog.js

@@ -396,7 +396,12 @@ function areElementsConnected( from, searchedElement ) {
 
 		// Handle arrays, maps, sets, custom collections that implements `[ Symbol.iterator ]()`, etc.
 		if ( node[ Symbol.iterator ] ) {
-			nodes.push( ...node );
+			// The custom editor iterators might cause some problems if the editor is crashed.
+			try {
+				nodes.push( ...node );
+			} catch ( err ) {
+				// eslint-disable-line no-empty
+			}
 		} else {
 			nodes.push( ...Object.values( node ) );
 		}

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

@@ -0,0 +1,15 @@
+<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>
+
+<div id="editor-1">
+	<h2>Heading 1</h2>
+	<p>Paragraph</p>
+</div>
+
+<div id="editor-2">
+	<h2>Heading 1</h2>
+	<p>Paragraph</p>
+</div>

+ 83 - 0
packages/ckeditor5-watchdog/tests/manual/watchdog.js

@@ -0,0 +1,83 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/* globals document, console */
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
+import Watchdog from '@ckeditor/ckeditor5-watchdog/src/watchdog';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
+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' );
+
+const editorConfig = {
+	plugins: [
+		ArticlePluginSet,
+	],
+	toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote',
+		'insertTable', 'mediaEmbed', 'undo', 'redo' ],
+	table: {
+		contentToolbar: [
+			'tableColumn',
+			'tableRow',
+			'mergeTableCells'
+		]
+	}
+};
+
+// Watchdog 1
+
+const watchdog1 = Watchdog.for( ClassicEditor );
+
+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( 'crash', () => {
+	console.log( 'First editor crashed!' );
+} );
+
+watchdog1.on( 'restart', () => {
+	console.log( 'First editor restarted.' );
+} );
+
+// Watchdog 2
+
+const watchdog2 = Watchdog.for( ClassicEditor );
+
+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( 'crash', () => {
+	console.log( 'Second editor crashed!' );
+} );
+
+watchdog2.on( 'restart', () => {
+	console.log( 'Second editor restarted.' );
+} );
+
+restartButton.addEventListener( 'click', () => {
+	watchdog1.restart();
+	watchdog2.restart();
+} );
+
+randomErrorButton.addEventListener( 'click', () => {
+	throw new Error( 'foo' );
+} );

+ 9 - 0
packages/ckeditor5-watchdog/tests/manual/watchdog.md

@@ -0,0 +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. Simulate the 2nd editor crash with the button. Only the second editor should be restarted. The error should be logged in the console.
+
+1. 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. Run `restart both editor`. Both editors should be restarted.