Procházet zdrojové kódy

Added test and documentation for plugins.

fredck před 10 roky
rodič
revize
ecf7fe94fc
3 změnil soubory, kde provedl 42 přidání a 2 odebrání
  1. 3 2
      package.json
  2. 6 0
      src/plugin.js
  3. 33 0
      tests/plugin/plugin.js

+ 3 - 2
package.json

@@ -8,8 +8,9 @@
     "WYSIWYG"
   ],
   "dependencies": {
-    "requirejs": "~2.1",
-    "ckeditor5-core": "ckeditor/ckeditor5-core"
+    "ckeditor5-core": "ckeditor/ckeditor5-core",
+    "ckeditor5-plugin-devtest": "ckeditor/ckeditor5-plugin-devtest",
+    "requirejs": "~2.1"
   },
   "devDependencies": {
     "almond": "~0.3.0",

+ 6 - 0
src/plugin.js

@@ -18,15 +18,21 @@ define( 'plugin', [ 'plugin-core' ], function( CorePlugin ) {
 	// Called when a "plugin!" module is to be loaded.
 	// http://requirejs.org/docs/plugins.html#apiload
 	CorePlugin.load = function( name, require, onload ) {
+		// We may have a path to plugin modules (e.g. test/somemodule). Here we break the path on slashes.
 		var path = name.split( '/' );
+
+		// Inject the /src/ part right after the plugin name (e.g test/src).
 		path.splice( 1, 0, 'src' );
 
+		// If we didn't have any subpart in the path, inject the plugin name at the end (e.g. test/src/test).
 		if ( path.length == 2 ) {
 			path.push( path[ 0 ] );
 		}
 
+		// Finally point to the right place, relatively to the `ckeditor5-core/src` directory (in node_modules).
 		path = '../../ckeditor5-plugin-' + path.join( '/' );
 
+		// Now require the module again, using the fully resolved path.
 		require( [ path ], onload, onload.error );
 	};
 

+ 33 - 0
tests/plugin/plugin.js

@@ -0,0 +1,33 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals describe, it, expect, CKEDITOR */
+
+'use strict';
+
+describe( 'CKEDITOR.require()', function() {
+	it( 'should load a CKEditor plugin', function( done ) {
+		CKEDITOR.require( [ 'plugin!devtest' ], function( DevTest ) {
+			expect( DevTest ).to.have.property( 'isDevTest' );
+			done() ;
+		} );
+	} );
+
+	it( 'should load dependencies on CKEditor plugins', function( done ) {
+		CKEDITOR.require( [ 'plugin!devtest/someclass' ], function( SomeClass ) {
+			expect( SomeClass ).to.have.property( 'isSomeClass' );
+			done() ;
+		} );
+	} );
+
+	it( 'should load a dependency into a CKEditor plugin', function( done ) {
+		CKEDITOR.require( [ 'plugin!devtest', 'plugin!devtest/someclass' ], function( DevTest, SomeClass ) {
+			var test = new DevTest();
+
+			expect( test ).to.have.property( 'someProperty' ).to.be.an.instanceof( SomeClass );
+			done() ;
+		} );
+	} );
+} );