Bladeren bron

Removed `Context.for()` static method.

Maciej Bukowski 5 jaren geleden
bovenliggende
commit
243c37d632

+ 50 - 45
packages/ckeditor5-watchdog/docs/features/watchdog.md

@@ -154,34 +154,36 @@ import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
 import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
 import Context from '@ckeditor/ckeditor5-core/src/context';
 
-// Create a watchdog for the context and pass the context configuration:
-const watchdog = ContextWatchdog.for( Context, {
-	plugins: [],
-
-	// Rest of the configuration.
+// Create a watchdog for the context and pass the `Context` class with optional watchdog configuration:
+const watchdog = new ContextWatchdog( Context, {
+	crashNumberLimit: 10
 } );
 
+// Initialize it with the context configuration:
+await watchdog.create( {
+	plugins: []
+} )
+
 // Add editor instances:
-watchdog.add( {
-	editor1: {
-		type: 'editor',
-		sourceElementOrData: document.querySelector( '#editor' ),
-		config: {
-			plugins: [ Essentials, Paragraph, Bold, Italic ],
-			toolbar: [ 'bold', 'italic', 'alignment' ]
-		},
-		creator: ( element, config ) => ClassicEditor.create( element, config )
+await watchdog.add( [ {
+	id: 'editor1',
+	type: 'editor',
+	sourceElementOrData: document.querySelector( '#editor' ),
+	config: {
+		plugins: [ Essentials, Paragraph, Bold, Italic ],
+		toolbar: [ 'bold', 'italic', 'alignment' ]
 	},
-	editor2: {
-		type: 'editor',
-		sourceElementOrData: document.querySelector( '#editor' ),
-		config: {
-			plugins: [ Essentials, Paragraph, Bold, Italic ],
-			toolbar: [ 'bold', 'italic', 'alignment' ]
-		},
-		creator: ( element, config ) => ClassicEditor.create( element, config )
+	creator: ( element, config ) => ClassicEditor.create( element, config )
+}, {
+	id: 'editor2',
+	type: 'editor',
+	sourceElementOrData: document.querySelector( '#editor' ),
+	config: {
+		plugins: [ Essentials, Paragraph, Bold, Italic ],
+		toolbar: [ 'bold', 'italic', 'alignment' ]
 	},
-} );
+	creator: ( element, config ) => ClassicEditor.create( element, config )
+} ] );
 ```
 
 The Watchdog will keep the context and editor instances running
@@ -190,7 +192,11 @@ that are added via the {@link module:watchdog/contextwatchdog~ContextWatchdog#ad
 To destroy one of the editor instances use the {@link module:watchdog/contextwatchdog~ContextWatchdog#remove `ContextWatchdog#remove` method}. This method can be called multiple times during the `ContextWatchdog` lifetime as well.
 
 ```js
-watchdog.remove( [ 'editor1' ] );
+await watchdog.remove( [ 'editor1', 'editor2' ] );
+
+// Or
+await watchdog.remove( 'editor1' );
+await watchdog.remove( 'editor2' );
 ```
 
 <info-box>
@@ -202,12 +208,10 @@ watchdog.remove( [ 'editor1' ] );
 The ContextWatchdog feature provides the following API:
 
 ```js
-// A simple initialization with default Context creation and destruction functions:
-const watchdog = ContextWatchdog.for( Context, contextConfig, watchdogConfig )
-
-// An advanced initialization where custom creation and destruction functions can be passed:
-const watchdog = new ContextWatchdog( contextConfig, watchdogConfig )
+// Create watchdog that will use the `Context` class and given configuration.
+const watchdog = new ContextWatchdog( Context, watchdogConfig );
 
+// Set a custom creator.
 watchdog.setCreator( async config => {
 	const context = await Context.create( config ) );
 
@@ -216,35 +220,36 @@ watchdog.setCreator( async config => {
 	return context;
 } );
 
+// Set a custom destructor.
 watchdog.setDestructor( async context => {
 	// Do something before destroy.
 
 	await context.destroy();
 } );
 
-watchdog.create();
-
-// Adding, removing and getting item instances:
-watchdog.add( {
-	editor1: {
-		type: 'editor',
-		sourceElementOrData: editorSourceElementOrEditorData
-		config: editorConfig,
-		creator: createEditor,
-		destructor: destroyEditor,
-	},
-	// Possibly more items.
+// Initialize the context watchdog with the context configuration.
+await watchdog.create( contextConfig );
+
+// Add editor configuration.
+await watchdog.add( {
+	id: 'editor1',
+	type: 'editor',
+	sourceElementOrData: editorSourceElementOrEditorData
+	config: editorConfig,
+	creator: createEditor,
+	destructor: destroyEditor,
 } );
 
-watchdog.remove( [ 'editor1' ] );
+// Remove and destroy given editor.
+await watchdog.remove( [ 'editor1' ] );
 
-// Given item instance.
+// Get given item instance.
 const editor1 = watchdog.get( 'editor1' );
 
-// Given item state.
+// Get given item state.
 const editor1State = watchdog.getState( 'editor1' );
 
-// Context state.
+// Get the context state.
 const contextState = watchdog.state;
 
 // An event fired when the context watchdog catches the context-related error.

+ 48 - 77
packages/ckeditor5-watchdog/src/contextwatchdog.js

@@ -22,13 +22,20 @@ import getSubNodes from './utils/getsubnodes';
  */
 export default class ContextWatchdog extends Watchdog {
 	/**
-	 * The ContextWatchdog constructor. See {@glink features/watchdog Watchdog feature guide} to learn how to use it,
-	 * as using the constructor directly requires further steps to initialize the `ContextWatchdog`.
+	 * The `ContextWatchdog` class constructor.
 	 *
-	 * @param {Object} [contextConfig] {@link module:core/context~Context} configuration.
+	 * 	const contextWatchdog = new ContextWatchdog( Context );
+	 *
+	 * 	await contextWatchdog.create( contextConfiguration );
+	 *
+	 * 	await contextWatchdog.add( watchdogItem );
+	 *
+	 * See {@glink features/watchdog the watchdog feature guide} to learn more how to use this feature.
+	 *
+	 * @param {Function} Context The {@link module:core/context~Context} class.
 	 * @param {module:watchdog/watchdog~WatchdogConfig} [watchdogConfig] The watchdog configuration.
 	 */
-	constructor( contextConfig = {}, watchdogConfig = {} ) {
+	constructor( Context, watchdogConfig = {} ) {
 		super( watchdogConfig );
 
 		/**
@@ -76,9 +83,8 @@ export default class ContextWatchdog extends Watchdog {
 		 * Config for the {@link module:core/context~Context}.
 		 *
 		 * @private
-		 * @type {Object}
+		 * @member {Object} #_contextConfig
 		 */
-		this._contextConfig = contextConfig;
 
 		/**
 		 * The context configuration.
@@ -87,7 +93,8 @@ export default class ContextWatchdog extends Watchdog {
 		 * @member {Object|undefined} #_config
 		 */
 
-		// Default destructor.
+		// Default creator and destructor.
+		this._creator = contextConfig => Context.create( contextConfig );
 		this._destructor = context => context.destroy();
 
 		this._actionQueue.onEmpty( () => {
@@ -108,7 +115,22 @@ export default class ContextWatchdog extends Watchdog {
 	}
 
 	/**
-     * Returns the item instance with the given `id`.
+	 * Initializes the context watchdog. Once it's created the watchdog takes care about
+	 * recreating the context and provided items and starts the error handling mechanism.
+	 *
+	 * @param {Object} [contextConfig] Context configuration. See {@link module:core/context~Context}.
+	 * @returns {Promise}
+	 */
+	create( contextConfig = {} ) {
+		return this._actionQueue.enqueue( () => {
+			this._contextConfig = contextConfig;
+
+			return this._create();
+		} );
+	}
+
+	/**
+     * Returns the item instance with the given `itemId`.
 	 *
 	 * 	const editor1 = contextWatchdog.get( 'editor1' );
 	 *
@@ -122,7 +144,7 @@ export default class ContextWatchdog extends Watchdog {
 	}
 
 	/**
-	 * Gets state of the given item. For the list of available state see {@link #state}.
+	 * Gets state of the given item. For the list of available states see {@link #state}.
 	 *
 	 * @param {String} itemId Item id.
 	 * @returns {'initializing'|'ready'|'crashed'|'crashedPermanently'|'destroyed'} The state of the item.
@@ -255,17 +277,6 @@ export default class ContextWatchdog extends Watchdog {
 	}
 
 	/**
-	 * Creates the Context watchdog.
-	 *
-	 * @returns {Promise}
-	 */
-	create() {
-		return this._actionQueue.enqueue( () => {
-			return this._create();
-		} );
-	}
-
-	/**
 	 * Destroys the `ContextWatchdog` and all added items.
 	 * Once the `ContextWatchdog` is destroyed new items can not be added.
 	 *
@@ -386,70 +397,32 @@ export default class ContextWatchdog extends Watchdog {
 		// Ignore cases when the error comes from editors.
 		return areConnectedThroughProperties( this._contextProps, error.context );
 	}
-
-	/**
-	 * Creates context watchdog for the given Context constructor, context configuration and watchdog configuration.
-	 *
-	 * 	const contextWatchdog = ContextWatchdog.for( Context, {
-	 * 		plugins: []
-	 * 	} );
-	 *
-	 * 	contextWatchdog.add( watchdogItem );
-	 *
-	 * @param {module:core/context~Context} Context
-	 * @param {Object} [contextConfig]
-	 * @param {module:watchdog/watchdog~WatchdogConfig} [watchdogConfig]
-	 * @returns {module:watchdog/contextwatchdog~ContextWatchdog}
-	 */
-	static for( Context, contextConfig, watchdogConfig ) {
-		const watchdog = new this( contextConfig, watchdogConfig );
-
-		watchdog.setCreator( config => Context.create( config ) );
-
-		watchdog.create();
-
-		return watchdog;
-	}
 }
 
-/**
- * An action queue that allows queuing async functions.
- *
- * @private
- */
+// An action queue that allows queuing async functions.
 class ActionQueue {
 	constructor() {
-		/**
-		 * @type {Array.<Function>}
-		 */
+		// @type {Array.<Function>}
 		this._queuedActions = [];
 
-		/**
-		 * @type {WeakMap.<Function, Function>}
-		 */
+		// @type {WeakMap.<Function, Function>}
 		this._resolveCallbacks = new WeakMap();
 
-		/**
-		 * @type {Array.<Function>}
-		 */
+		// @type {Array.<Function>}
 		this._onEmptyCallbacks = [];
 	}
 
-	/**
-	 * A method used to register callbacks that will be run when the queue becomes empty.
-	 *
-	 * @param {Function} onEmptyCallback A callback that will be run whenever the queue becomes empty.
-	 */
+	// A method used to register callbacks that will be run when the queue becomes empty.
+	//
+	// @param {Function} onEmptyCallback A callback that will be run whenever the queue becomes empty.
 	onEmpty( onEmptyCallback ) {
 		this._onEmptyCallbacks.push( onEmptyCallback );
 	}
 
-	/**
-	 * It adds asynchronous actions (functions) to the queue and runs them one by one.
-	 *
-	 * @param {Function} action A function that should be enqueued.
-	 * @returns {Promise}
-	 */
+	// It adds asynchronous actions (functions) to the queue and runs them one by one.
+	//
+	// @param {Function} action A function that should be enqueued.
+	// @returns {Promise}
 	enqueue( action ) {
 		this._queuedActions.push( action );
 
@@ -466,13 +439,9 @@ class ActionQueue {
 		} );
 	}
 
-	/**
-	 * It handles queued actions one by one.
-	 *
-	 * @private
-	 * @param {Function} res
-	 * @param {Function} rej
-	 */
+	// It handles queued actions one by one.
+	// @param {Function} res
+	// @param {Function} rej
 	_handleActions( res, rej ) {
 		const action = this._queuedActions[ 0 ];
 
@@ -517,9 +486,11 @@ class ActionQueue {
  *
  * @typedef {Object} module:watchdog/contextwatchdog~EditorWatchdogConfiguration
  *
+ * @property {string} id A unique item identificator.
+ *
  * @property {'editor'} type Type of the item to create. At the moment, only `'editor'` is supported.
  *
- * @property {Function} creator A function that initializes the editor.
+ * @property {Function} [creator] A function that initializes the editor.
  *
  * @property {Function} [destructor] A function that destroys the editor.
  *

+ 79 - 75
packages/ckeditor5-watchdog/tests/contextwatchdog.js

@@ -36,7 +36,9 @@ describe( 'ContextWatchdog', () => {
 	} );
 
 	it( 'should disable adding items once the ContextWatchdog is destroyed', async () => {
-		watchdog = ContextWatchdog.for( Context, {} );
+		watchdog = new ContextWatchdog( Context );
+
+		watchdog.create();
 
 		await watchdog.destroy();
 
@@ -60,9 +62,9 @@ describe( 'ContextWatchdog', () => {
 
 	describe( 'for scenario with no items', () => {
 		it( 'should create only context', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
 
-			await watchdog.waitForReady();
+			await watchdog.create();
 
 			expect( watchdog.context ).to.be.instanceOf( Context );
 
@@ -70,11 +72,13 @@ describe( 'ContextWatchdog', () => {
 		} );
 
 		it( 'should have proper states', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
+
+			const initializationPromise = watchdog.create();
 
 			expect( watchdog.state ).to.equal( 'initializing' );
 
-			await watchdog.waitForReady();
+			await initializationPromise;
 
 			expect( watchdog.state ).to.equal( 'ready' );
 
@@ -83,13 +87,18 @@ describe( 'ContextWatchdog', () => {
 			expect( watchdog.state ).to.equal( 'destroyed' );
 		} );
 
-		it( 'should set custom destructor if provided', async () => {
-			const mainWatchdog = new ContextWatchdog();
+		it( 'should set custom creator and destructor if provided', async () => {
+			const mainWatchdog = new ContextWatchdog( Context );
+
+			const customCreator = sinon.spy( config => Context.create( config ) );
 			const customDestructor = sinon.spy( context => context.destroy() );
 
-			mainWatchdog.setCreator( config => Context.create( config ) );
+			mainWatchdog.setCreator( customCreator );
 			mainWatchdog.setDestructor( customDestructor );
-			mainWatchdog.create();
+
+			await mainWatchdog.create();
+
+			sinon.assert.calledOnce( customCreator );
 
 			await mainWatchdog.destroy();
 
@@ -97,11 +106,11 @@ describe( 'ContextWatchdog', () => {
 		} );
 
 		it( 'should log if an error happens during the component destructing', async () => {
-			const mainWatchdog = new ContextWatchdog();
+			const mainWatchdog = new ContextWatchdog( Context );
 
 			const consoleErrorStub = sinon.stub( console, 'error' );
 			const err = new Error( 'foo' );
-			mainWatchdog.setCreator( config => Context.create( config ) );
+
 			mainWatchdog.setDestructor( async editor => {
 				await editor.destroy();
 
@@ -109,7 +118,6 @@ describe( 'ContextWatchdog', () => {
 			} );
 
 			await mainWatchdog.create();
-
 			await mainWatchdog._restart();
 
 			sinon.assert.calledWith(
@@ -125,7 +133,7 @@ describe( 'ContextWatchdog', () => {
 
 		it( 'should handle the Watchdog configuration', async () => {
 			// TODO
-			const mainWatchdog = ContextWatchdog.for( Context, {}, {
+			const mainWatchdog = new ContextWatchdog( Context, {
 				crashNumberLimit: Infinity
 			} );
 
@@ -136,10 +144,11 @@ describe( 'ContextWatchdog', () => {
 
 		describe( 'in case of error handling', () => {
 			it( 'should restart the `Context`', async () => {
-				watchdog = ContextWatchdog.for( Context, {} );
+				watchdog = new ContextWatchdog( Context );
+
 				const errorSpy = sinon.spy();
 
-				await watchdog.waitForReady();
+				await watchdog.create();
 
 				const oldContext = watchdog.context;
 
@@ -158,7 +167,9 @@ describe( 'ContextWatchdog', () => {
 
 	describe( 'for multiple items scenario', () => {
 		it( 'should allow adding multiple items without waiting for promises', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
+
+			watchdog.create();
 
 			watchdog.add( {
 				id: 'editor1',
@@ -174,34 +185,29 @@ describe( 'ContextWatchdog', () => {
 				config: {}
 			} );
 
-			// TODO
-			await watchdog.waitForReady();
-
 			await watchdog.destroy();
 		} );
 
 		it( 'should throw when multiple items with the same id are added', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
 
-			watchdog.add( {
+			await watchdog.create();
+
+			const editorItemConfig = {
 				id: 'editor1',
 				type: 'editor',
 				creator: ( el, config ) => ClassicTestEditor.create( el, config ),
 				sourceElementOrData: element1,
 				config: {}
-			} );
+			};
 
-			await watchdog.waitForReady();
+			const editorCreationPromise1 = watchdog.add( editorItemConfig );
+			const editorCreationPromise2 = watchdog.add( editorItemConfig );
 
 			let err;
 			try {
-				await watchdog.add( {
-					id: 'editor1',
-					type: 'editor',
-					creator: ( el, config ) => ClassicTestEditor.create( el, config ),
-					sourceElementOrData: element1,
-					config: {}
-				} );
+				await editorCreationPromise1;
+				await editorCreationPromise2;
 			} catch ( _err ) {
 				err = _err;
 			}
@@ -213,9 +219,9 @@ describe( 'ContextWatchdog', () => {
 		} );
 
 		it( 'should throw when not added item is removed', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
 
-			await watchdog.waitForReady();
+			await watchdog.create();
 
 			let err;
 
@@ -232,7 +238,7 @@ describe( 'ContextWatchdog', () => {
 		} );
 
 		it( 'should throw when the item is added before the context is created', async () => {
-			const mainWatchdog = new ContextWatchdog( {}, {} );
+			const mainWatchdog = new ContextWatchdog( Context );
 
 			let err;
 			try {
@@ -248,7 +254,9 @@ describe( 'ContextWatchdog', () => {
 		} );
 
 		it( 'should allow setting editor custom destructors', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
+
+			watchdog.create();
 
 			const destructorSpy = sinon.spy( editor => editor.destroy() );
 
@@ -267,9 +275,9 @@ describe( 'ContextWatchdog', () => {
 		} );
 
 		it( 'should throw when the item is of not known type', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
 
-			await watchdog.waitForReady();
+			await watchdog.create();
 
 			let err;
 			try {
@@ -292,7 +300,9 @@ describe( 'ContextWatchdog', () => {
 		} );
 
 		it( 'should allow adding and removing items without waiting', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
+
+			watchdog.create();
 
 			watchdog.add( [ {
 				id: 'editor1',
@@ -308,23 +318,17 @@ describe( 'ContextWatchdog', () => {
 				config: {}
 			} ] );
 
-			await watchdog.waitForReady();
-
-			expect( watchdog.state ).to.equal( 'ready' );
-
 			watchdog.remove( [ 'editor1' ] );
 
-			await watchdog.waitForReady();
-
 			watchdog.remove( [ 'editor2' ] );
 
-			await watchdog.waitForReady();
-
 			await watchdog.destroy();
 		} );
 
 		it( 'should not change the input items', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
+
+			watchdog.create();
 
 			watchdog.add( Object.freeze( [ {
 				id: 'editor1',
@@ -334,17 +338,17 @@ describe( 'ContextWatchdog', () => {
 				config: {}
 			} ] ) );
 
-			watchdog._restart();
-
-			await watchdog.waitForReady();
+			await watchdog._restart();
 
 			await watchdog.destroy();
 		} );
 
 		it( 'should return the created items instances with ContextWatchdog#get( itemId )', async () => {
-			watchdog = ContextWatchdog.for( Context, {} );
+			watchdog = new ContextWatchdog( Context );
 
-			watchdog.add( [ {
+			watchdog.create();
+
+			await watchdog.add( [ {
 				id: 'editor1',
 				type: 'editor',
 				creator: ( el, config ) => ClassicTestEditor.create( el, config ),
@@ -358,8 +362,6 @@ describe( 'ContextWatchdog', () => {
 				config: {}
 			} ] );
 
-			await watchdog.waitForReady();
-
 			expect( watchdog.get( 'editor1' ) ).to.be.instanceOf( ClassicTestEditor );
 			expect( watchdog.get( 'editor2' ) ).to.be.instanceOf( ClassicTestEditor );
 
@@ -376,8 +378,11 @@ describe( 'ContextWatchdog', () => {
 
 		describe( 'in case of error handling', () => {
 			it( 'should restart the whole structure of editors if an error happens inside the `Context`', async () => {
-				watchdog = ContextWatchdog.for( Context, {} );
-				watchdog.add( [ {
+				watchdog = new ContextWatchdog( Context );
+
+				await watchdog.create();
+
+				await watchdog.add( [ {
 					id: 'editor1',
 					type: 'editor',
 					creator: ( el, config ) => ClassicTestEditor.create( el, config ),
@@ -385,8 +390,6 @@ describe( 'ContextWatchdog', () => {
 					config: {}
 				} ] );
 
-				await watchdog.waitForReady();
-
 				const oldContext = watchdog.context;
 				const restartSpy = sinon.spy();
 
@@ -405,8 +408,11 @@ describe( 'ContextWatchdog', () => {
 			} );
 
 			it( 'should restart only the editor if an error happens inside the editor', async () => {
-				watchdog = ContextWatchdog.for( Context, {} );
-				watchdog.add( {
+				watchdog = new ContextWatchdog( Context );
+
+				await watchdog.create();
+
+				await watchdog.add( {
 					id: 'editor1',
 					type: 'editor',
 					creator: ( el, config ) => ClassicTestEditor.create( el, config ),
@@ -414,8 +420,6 @@ describe( 'ContextWatchdog', () => {
 					config: {}
 				} );
 
-				await watchdog.waitForReady();
-
 				const oldContext = watchdog.context;
 				const restartSpy = sinon.spy();
 
@@ -437,9 +441,11 @@ describe( 'ContextWatchdog', () => {
 			} );
 
 			it( 'should restart only the editor if an error happens inside one of the editors', async () => {
-				watchdog = ContextWatchdog.for( Context, {} );
+				watchdog = new ContextWatchdog( Context );
 
-				watchdog.add( [ {
+				await watchdog.create();
+
+				await watchdog.add( [ {
 					id: 'editor1',
 					type: 'editor',
 					creator: ( el, config ) => ClassicTestEditor.create( el, config ),
@@ -453,8 +459,6 @@ describe( 'ContextWatchdog', () => {
 					config: {}
 				} ] );
 
-				await watchdog.waitForReady();
-
 				const oldContext = watchdog.context;
 
 				const editorWatchdog1 = watchdog._watchdogs.get( 'editor1' );
@@ -493,9 +497,11 @@ describe( 'ContextWatchdog', () => {
 			} );
 
 			it( 'should handle removing and restarting at the same time', async () => {
-				watchdog = ContextWatchdog.for( Context, {} );
+				watchdog = new ContextWatchdog( Context );
+
+				await watchdog.create();
 
-				watchdog.add( [ {
+				await watchdog.add( [ {
 					id: 'editor1',
 					type: 'editor',
 					creator: ( el, config ) => ClassicTestEditor.create( el, config ),
@@ -509,16 +515,14 @@ describe( 'ContextWatchdog', () => {
 					config: {}
 				} ] );
 
-				await watchdog.waitForReady();
-
 				const editor1 = watchdog.get( 'editor1' );
 
-				watchdog.remove( [ 'editor1' ] );
+				const removePromise = watchdog.remove( [ 'editor1' ] );
 
 				setTimeout( () => throwCKEditorError( 'foo', editor1 ) );
 
 				await waitCycle();
-				await watchdog.waitForReady();
+				await removePromise;
 
 				expect( [ ...watchdog._watchdogs.keys() ] ).to.include( 'editor2' );
 				expect( [ ...watchdog._watchdogs.keys() ] ).to.not.include( 'editor1' );
@@ -527,9 +531,11 @@ describe( 'ContextWatchdog', () => {
 			} );
 
 			it( 'should handle restarting the item instance many times', async () => {
-				watchdog = ContextWatchdog.for( Context, {} );
+				watchdog = new ContextWatchdog( Context );
+
+				await watchdog.create();
 
-				watchdog.add( [ {
+				await watchdog.add( [ {
 					id: 'editor1',
 					type: 'editor',
 					creator: ( el, config ) => ClassicTestEditor.create( el, config ),
@@ -543,8 +549,6 @@ describe( 'ContextWatchdog', () => {
 					config: {}
 				} ] );
 
-				await watchdog.waitForReady();
-
 				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );
 				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );
 				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );