浏览代码

Merge branch 'master' into t/260

Piotrek Koszuliński 9 年之前
父节点
当前提交
8f7f97b0cb
共有 6 个文件被更改,包括 130 次插入256 次删除
  1. 1 1
      dev/bender/plugins/ckeditor5/lib/index.js
  2. 128 1
      dev/bender/plugins/ckeditor5/static/extensions.js
  3. 0 164
      dev/tasks/test/tasks.js
  4. 0 77
      dev/tests/test/tasks.js
  5. 0 2
      gulpfile.js
  6. 1 11
      package.json

+ 1 - 1
dev/bender/plugins/ckeditor5/lib/index.js

@@ -18,7 +18,7 @@ module.exports = {
 
 		this.on( 'test:created', ( test ) => {
 			const moduleRegExp = /^([^\/]+)\//;
-			let name = test.displayName.replace( /^build\/amd\/tests\//, '' );
+			let name = test.displayName.replace( /^build\/modules\/amd\/tests\//, '' );
 			let module = name.match( moduleRegExp );
 
 			if ( module ) {

+ 128 - 1
dev/bender/plugins/ckeditor5/static/extensions.js

@@ -8,7 +8,7 @@
 
 'use strict';
 
-( () => {
+( function() {
 	// This seems to be the only way to force Require.JS to load modules starting with '/' from a different path.
 	var load = requirejs.load;
 	requirejs.load = function( context, moduleId, url ) {
@@ -21,6 +21,39 @@
 		return load( context, moduleId, url );
 	};
 
+	// Extend ChaiJS with custom exception check `expect().to.throwCKEditorError( [ msg ] )`.
+	require( [ '/ckeditor5/utils/ckeditorerror.js', 'chai' ], function( CKEditorError, chai ) {
+		CKEditorError = CKEditorError.default;
+
+		// Load extension and bind class used to check for inheritance.
+		chai.use( addThrowsCKEditorError.bind( null, CKEditorError ) );
+
+		// Self-test of the extension. Function names will help find those tests in case of regression.
+		chai.expect( function throwCKEditorErrorSelfTest1() {
+			throw new CKEditorError();
+		} ).to.throwCKEditorError();
+
+		chai.expect( function throwCKEditorErrorSelfTest2() {
+			throw new Error();
+		} ).to.not.throwCKEditorError();
+
+		chai.expect( function throwCKEditorErrorSelfTest3() {
+			throw new CKEditorError( 'custom message' );
+		} ).to.throwCKEditorError( 'message' );
+
+		chai.expect( function throwCKEditorErrorSelfTest4() {
+			throw new CKEditorError( 'another msg' );
+		} ).to.throwCKEditorError( /msg/ );
+
+		chai.expect( function throwCKEditorErrorSelfTest5() {
+			throw new CKEditorError( 'another msg' );
+		} ).to.throwCKEditorError( /^another/ );
+
+		chai.expect( function throwCKEditorErrorSelfTest6() {
+			throw new CKEditorError( 'another msg' );
+		} ).to.throwCKEditorError( /msg$/ );
+	} );
+
 	// Reported: https://github.com/benderjs/benderjs/issues/248
 	// Ugh... make some paths cleanup, because we need to combine these fragments and we don't want to
 	// duplicate '/'. BTW. if you want to touch this make sure you haven't broken Bender jobs which
@@ -46,4 +79,98 @@
 	function nonEmpty( str ) {
 		return !!str.length;
 	}
+
+	// Add `throwCKEditorError` chainable method to ChaiJS.
+	//
+	// @param {Object} CKEditorError Constructor of class checking for CKEditorError membership.
+	// @param {Object} _chai Chai instance.
+	// @param {Object} utils Chai extension utils.
+	// @returns {Object} Assertion
+	function addThrowsCKEditorError( CKEditorError, _chai, utils ) {
+		var Assertion = _chai.Assertion;
+
+		Assertion.addMethod( 'throwCKEditorError', assertThrowCKEditorError );
+
+		function assertThrowCKEditorError( errMsg ) {
+			// jshint validthis: true
+			// jscs:disable disallowMultipleVarDecl
+
+			var obj = utils.flag( this, 'object' ),
+				actuallyGot = '',
+				thrown = false,
+				thrownError = null,
+				message;
+
+			if ( arguments.length === 0 ) {
+				errMsg = null;
+			}
+
+			try {
+				obj();
+			} catch ( err ) {
+				this.assert(
+					CKEditorError.isCKEditorError( err ),
+					'expected #{this} to throw #{exp} but #{act} was thrown',
+					'expected #{this} to not throw #{exp} but #{act} was thrown',
+					'CKEditorError',
+					( err instanceof Error ? err.toString() : err )
+				);
+
+				// Set subject of assertion.
+				if ( !errMsg ) {
+					utils.flag( this, 'object', err );
+
+					return this;
+				}
+
+				// Check message of error.
+				message = utils.type( err ) === 'object' && 'message' in err ? err.message : err.toString();
+
+				if ( ( message !== null && message !== undefined ) && errMsg && errMsg instanceof RegExp ) {
+					this.assert(
+						errMsg.exec( message ),
+						'expected #{this} to throw CKEditorError matching #{exp} but got #{act}',
+						'expected #{this} to throw CKEditorError not matching #{exp}',
+						errMsg,
+						message
+					);
+
+					utils.flag( this, 'object', err );
+
+					return this;
+				} else if ( ( message !== null && message !== undefined ) && errMsg && typeof errMsg == 'string' ) {
+					this.assert(
+						message.indexOf( errMsg ) !== -1,
+						'expected #{this} to throw CKEditorError including #{exp} but got #{act}',
+						'expected #{this} to throw CKEditorError not including #{act}',
+						errMsg,
+						message
+					);
+
+					utils.flag( this, 'object', err );
+
+					return this;
+				} else {
+					thrown = true;
+					thrownError = err;
+				}
+			}
+
+			if ( thrown ) {
+				actuallyGot = ' but #{act} was thrown';
+			}
+
+			this.assert(
+				thrown === true,
+					'expected #{this} to throw an CKEditorError' + actuallyGot,
+					'expected #{this} to not throw an CKEditorError' + actuallyGot,
+					'CKEditorError',
+					( thrownError instanceof Error ? thrownError.toString() : thrownError )
+			);
+
+			utils.flag( this, 'object', thrownError );
+
+			return this;
+		}
+	}
 } )();

+ 0 - 164
dev/tasks/test/tasks.js

@@ -1,164 +0,0 @@
-/* jshint node: true, esnext: true */
-
-'use strict';
-
-const gulp = require( 'gulp' );
-const istanbul = require( 'gulp-istanbul' );
-const gutil = require( 'gulp-util' );
-const mocha = require( 'gulp-mocha' );
-const chai = require( 'chai' );
-const filterBy = require( 'gulp-filter-by' );
-const filter = require( 'gulp-filter' );
-const sinon = require( 'sinon' );
-const semver = require( 'semver' );
-const { tools, stream } = require( 'ckeditor5-dev-utils' );
-const benderConfig = require( '../../../bender' );
-
-/**
- * Defines Node.js testing task and development tools testing tasks.
- *
- * To run tests under Node.js:
- *
- *		gulp test:node
- *
- * To run build under Node.js before testing:
- *
- *		gulp test:node:build
- *
- * To run testing under Node.js with code coverage:
- *
- *		gulp test:node:coverage
- *
- * To run development tools tests:
- *
- * 		gulp test:dev
- *
- * To run development tools tests with coverage:
- *
- * 		gulp test:dev:coverage
- */
-module.exports = () => {
-	const ignoreRegexp = /\/\* ?bender-tags:.*\bbrowser-only\b.*\*\//;
-
-	// Inject globals before running tests.
-	global.should = chai.should;
-	global.expect = chai.expect;
-	global.assert = chai.assert;
-	global.sinon = sinon;
-
-	const tasks = {
-		/**
-		 * Is set to `true` when code coverage report will be displayed.
-		 *
-		 * @type {Boolean}
-		 */
-		coverage: false,
-
-		/**
-		 * Prepares files for coverage report.
-		 *
-		 * @returns {Stream}
-		 */
-		prepareNodeCoverage() {
-			const src = benderConfig.coverage.paths.map( ( item ) => {
-				return item.replace( 'build/amd/', 'build/cjs/' );
-			} );
-			tasks.coverage = true;
-
-			return gulp.src( src )
-				.pipe( istanbul() )
-				.pipe( istanbul.hookRequire() );
-		},
-
-		/**
-		 * Runs tests in Node.js environment.
-		 *
-		 * @returns {Stream}
-		 */
-		testInNode() {
-			const minVersion = '6.0.0';
-
-			if ( semver.lt( process.version, minVersion ) ) {
-				throw new gutil.PluginError( {
-					plugin: 'test-node',
-					message: `Wrong Node.js version. Please use Node.js in version v${ minVersion } or higher.`
-				} );
-			}
-
-			const benderSrc = benderConfig.tests.all.paths.map( ( item ) => {
-				return item.replace( 'build/amd/', 'build/cjs/' ) + '/*.js' ;
-			} );
-
-			const src = [
-				...benderSrc,
-				'!build/cjs/tests/{ui,ui-*}/**/*.js',
-				'!build/cjs/tests/theme-*/**/*.js',
-				'!build/cjs/tests/creator-*/**/*.js'
-			];
-
-			return gulp.src( src )
-				.pipe( tasks.skipManual() )
-				.pipe( tasks.skipIgnored() )
-				.pipe( mocha( { reporter: 'progress' } ) )
-				.pipe( tasks.coverage ? istanbul.writeReports() : stream.noop() );
-		},
-
-		/**
-		 * Removes manual test files from source stream. It checks if the markdown file with the same name exists.
-		 *
-		 * @returns {Stream}
-		 */
-		skipManual() {
-			return filter( ( file ) => {
-				return !tools.isFile( file.path.slice( 0, -3 ) + '.md' );
-			} );
-		},
-
-		/**
-		 * Skips test files that are marked to be ignored when testing outside browser.
-		 * To ignore file, add `browser-only` to bender-tags comment in test file.
-		 *
-		 * @returns {Stream}
-		 */
-		skipIgnored() {
-			return filterBy( file => !file.contents.toString().match( ignoreRegexp ) );
-		},
-
-		/**
-		 * Runs dev unit tests.
-		 *
-		 * @returns {Stream}
-		 */
-		devTest() {
-			return gulp.src( 'dev/tests/**/*.js' )
-				.pipe( mocha() )
-				.pipe( tasks.coverage ? istanbul.writeReports() : stream.noop() );
-		},
-
-		/**
-		 * Prepares files for coverage report.
-		 *
-		 * @returns {Stream}
-		 */
-		prepareDevCoverage() {
-			tasks.coverage = true;
-
-			return gulp.src( 'dev/tasks/**/*.js' )
-				.pipe( istanbul() )
-				.pipe( istanbul.hookRequire() );
-		},
-
-		register() {
-			gulp.task( 'test:node:pre-coverage', [ 'build:js:cjs' ], tasks.prepareNodeCoverage );
-			gulp.task( 'test:node', tasks.testInNode );
-			gulp.task( 'test:node:build', [ 'build:js:cjs' ] , tasks.testInNode );
-			gulp.task( 'test:node:coverage', [ 'build:js:cjs', 'test:node:pre-coverage' ], tasks.testInNode );
-
-			gulp.task( 'test:dev:pre-coverage', tasks.prepareDevCoverage );
-			gulp.task( 'test:dev', tasks.devTest );
-			gulp.task( 'test:dev:coverage', [ 'test:dev:pre-coverage' ], tasks.devTest );
-		}
-	};
-
-	return tasks;
-};

+ 0 - 77
dev/tests/test/tasks.js

@@ -1,77 +0,0 @@
-/**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* global describe, it, sinon */
-
-'use strict';
-
-const Vinyl = require( 'vinyl' );
-const tasks = require( '../../tasks/test/tasks' )();
-const { stream: streamUtils, tools } = require( 'ckeditor5-dev-utils' );
-
-describe( 'test-node', () => {
-	describe( 'skipManual', () => {
-		it( 'should skip manual tests', ( done ) => {
-			const stream = tasks.skipManual();
-			const spy = sinon.spy();
-			const stub = sinon.stub( tools, 'isFile', ( file ) => {
-				return file == 'file1.md';
-			} );
-			const unitTestFile = new Vinyl( {
-				cwd: './',
-				path: 'file2.js',
-				contents: null
-			} );
-			const manualTestFile = new Vinyl( {
-				cwd: './',
-				path: 'file1.js',
-				contents: null
-			} );
-
-			stream.pipe( streamUtils.noop( spy ) );
-
-			stream.once( 'finish', () => {
-				sinon.assert.calledOnce( spy );
-				sinon.assert.calledWithExactly( spy, unitTestFile );
-				done();
-			} );
-
-			stream.write( manualTestFile );
-			stream.write( unitTestFile );
-
-			stream.end();
-			stub.restore();
-		} );
-	} );
-
-	describe( 'skipIgnored', () => {
-		it( 'should skip files marked to ignore', ( done ) => {
-			const stream = tasks.skipIgnored();
-			const spy = sinon.spy();
-			const unitTestFile = new Vinyl( {
-				cwd: './',
-				path: 'file2.js',
-				contents: new Buffer( '' )
-			} );
-			const manualTestFile = new Vinyl( {
-				cwd: './',
-				path: 'file1.js',
-				contents: new Buffer( '/* bender-tags: tag, browser-only */' )
-			} );
-			const noop = streamUtils.noop( spy );
-			noop.once( 'finish', () => {
-				sinon.assert.calledOnce( spy );
-				sinon.assert.calledWithExactly( spy, unitTestFile );
-				done();
-			} );
-
-			stream.pipe( noop );
-			stream.write( manualTestFile );
-			stream.write( unitTestFile );
-
-			stream.end();
-		} );
-	} );
-} );

+ 0 - 2
gulpfile.js

@@ -37,8 +37,6 @@ const config = {
 	]
 };
 
-require( './dev/tasks/test/tasks' )( config ).register();
-
 // Lint tasks.
 const ckeditor5Lint = require( 'ckeditor5-dev-lint' )( config );
 gulp.task( 'lint', ckeditor5Lint.lint );

+ 1 - 11
package.json

@@ -31,23 +31,13 @@
     "benderjs-mocha": "^0.3.0",
     "benderjs-promise": "^0.1.0",
     "benderjs-sinon": "^0.3.0",
-    "chai": "^3.4.0",
     "ckeditor5-dev-bundler-rollup": "ckeditor/ckeditor5-dev-bundler-rollup",
     "ckeditor5-dev-compiler": "ckeditor/ckeditor5-dev-compiler",
     "ckeditor5-dev-env": "ckeditor/ckeditor5-dev-env",
     "ckeditor5-dev-lint": "ckeditor/ckeditor5-dev-lint",
-    "ckeditor5-dev-utils": "ckeditor/ckeditor5-dev-utils",
     "gulp": "^3.9.0",
-    "gulp-filter": "^3.0.1",
-    "gulp-filter-by": "^1.2.0",
-    "gulp-istanbul": "^0.10.4",
-    "gulp-mocha": "^2.2.0",
-    "gulp-util": "^3.0.7",
     "guppy-pre-commit": "^0.3.0",
-    "run-sequence": "^1.1.5",
-    "semver": "^5.1.0",
-    "sinon": "^1.17.0",
-    "vinyl": "^1.1.1"
+    "run-sequence": "^1.1.5"
   },
   "engines": {
     "node": ">=6.0.0",