Procházet zdrojové kódy

Tests: Improved error forwarding tests.

Piotrek Koszuliński před 10 roky
rodič
revize
82e0267f0b

+ 29 - 2
packages/ckeditor5-engine/tests/plugincollection/plugincollection.js

@@ -10,6 +10,7 @@
 var modules = bender.amd.require( 'plugincollection', 'plugin', 'editor', 'log' );
 var editor;
 var PluginA, PluginB;
+class TestError extends Error {}
 
 var sandbox = sinon.sandbox.create();
 afterEach( sandbox.restore.bind( sandbox ) );
@@ -50,6 +51,10 @@ CKEDITOR.define( 'plugin!F', [ 'plugin', 'plugin!E' ], function( Plugin ) {
 	return class extends Plugin {};
 } );
 
+CKEDITOR.define( 'plugin!G', function() {
+	throw new TestError( 'Some error inside a plugin' );
+} );
+
 /////////////
 
 describe( 'load', function() {
@@ -170,7 +175,7 @@ describe( 'load', function() {
 			} );
 	} );
 
-	it( 'should throw an error for invalid plugins', function() {
+	it( 'should reject on invalid plugin names (forward require.js loading error)', function() {
 		var PluginCollection = modules.plugincollection;
 		var log = modules.log;
 
@@ -186,7 +191,29 @@ describe( 'load', function() {
 			.catch( function( err ) {
 				expect( err ).to.be.an.instanceof( Error );
 				// Make sure it's the Require.JS error, not the one thrown above.
-				expect( err ).to.have.property( 'requireType', 'scripterror' );
+				expect( err.message ).to.match( /^Script error for:/ );
+
+				sinon.assert.calledOnce( logSpy );
+				expect( logSpy.args[ 0 ][ 0 ] ).to.match( /^plugincollection-load:/ );
+			} );
+	} );
+
+	it( 'should reject on broken plugins (forward the error thrown in a plugin)', function() {
+		var PluginCollection = modules.plugincollection;
+		var log = modules.log;
+
+		var logSpy = sandbox.stub( log, 'error' );
+
+		var plugins = new PluginCollection( editor );
+
+		return plugins.load( 'A,G,B' )
+			// Throw here, so if by any chance plugins.load() was resolved correctly catch() will be stil executed.
+			.then( function() {
+				throw new Error( 'Test error: this promise should not be resolved successfully' );
+			} )
+			.catch( function( err ) {
+				expect( err ).to.be.an.instanceof( TestError );
+				expect( err ).to.have.property( 'message', 'Some error inside a plugin' );
 
 				sinon.assert.calledOnce( logSpy );
 				expect( logSpy.args[ 0 ][ 0 ] ).to.match( /^plugincollection-load:/ );