8
0
Эх сурвалжийг харах

Do not forget about stopping function execution after a promise was rejected.

Piotrek Koszuliński 10 жил өмнө
parent
commit
5419065026

+ 6 - 1
packages/ckeditor5-engine/src/plugincollection.js

@@ -78,7 +78,12 @@ CKEDITOR.define( [
 									 * @error plugincollection-instance
 									 * @param {String} plugin The name of the plugin that is not an instance of Plugin.
 									 */
-									reject( new CKEditorError( 'plugincollection-instance: The plugin is not an instance of Plugin.', { plugin: plugin } ) );
+									return reject(
+										new CKEditorError(
+											'plugincollection-instance: The plugin is not an instance of Plugin.',
+											{ plugin: plugin }
+										)
+									);
 								}
 
 								loadedPlugin.name = plugin;

+ 17 - 1
packages/ckeditor5-engine/tests/plugincollection/plugincollection.js

@@ -87,7 +87,9 @@ CKEDITOR.define( 'plugin!I', [ 'plugin', 'plugin!J' ], function( Plugin ) {
 
 // Note: This is NOT a plugin.
 CKEDITOR.define( 'plugin!J', function() {
-	return class {};
+	return function() {
+		return ( spies.jSpy = sinon.spy() );
+	};
 } );
 
 /////////////
@@ -313,6 +315,20 @@ describe( 'load', function() {
 				expect( err.message ).to.match( /^plugincollection-instance:/ );
 			} );
 	} );
+
+	it( 'should cancel loading module which looks like a plugin but is a normal module', function() {
+		var PluginCollection = modules.plugincollection;
+		var plugins = new PluginCollection( editor );
+
+		return plugins.load( 'J' )
+			.then( () => {
+				throw new Error( 'Test error: this promise should not be resolved successfully' );
+			} ).catch( () => {
+				// Path would be set if code execution wasn't stopped when we rejected the promise
+				// (based on a real mistake we've made).
+				expect( spies.jSpy.path ).to.be.undefined;
+			} );
+	} );
 } );
 
 describe( 'add', function() {