8
0
Просмотр исходного кода

Added new gulp taks test-editor.

Szymon Kupś 10 лет назад
Родитель
Сommit
77f30c8cc9
4 измененных файлов с 151 добавлено и 0 удалено
  1. 69 0
      dev/tasks/test/tasks.js
  2. 78 0
      dev/tests/test/tasks.js
  3. 1 0
      gulpfile.js
  4. 3 0
      package.json

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

@@ -0,0 +1,69 @@
+/* jshint node: true, esnext: true */
+
+'use strict';
+
+const gulp = require( 'gulp' );
+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 minimist = require( 'minimist' );
+const devTools = require( '../dev/utils/tools' );
+
+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 = {
+		testEditor() {
+			const options = minimist( process.argv.slice( 2 ), {
+				boolean: [ 'node' ],
+				default: {
+					'node': false
+				}
+			} );
+
+			if ( options.node ) {
+				return tasks.testInNode();
+			}
+		},
+
+		testInNode() {
+			return gulp.src( 'dist/cjs/tests/**/*.js' )
+				.pipe( tasks.skipManual() )
+				.pipe( tasks.skipIgnored() )
+				.pipe( mocha() );
+		},
+
+		/**
+		 * 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 !devTools.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 ) );
+		}
+	};
+
+	gulp.task( 'test-editor', tasks.testEditor );
+
+	return tasks;
+};

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

@@ -0,0 +1,78 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global describe, it, sinon */
+
+'use strict';
+
+const tasks = require( '../../tasks/test/tasks' )();
+const buildUtils = require( '../../tasks/build/utils' );
+const devTools = require( '../../tasks/dev/utils/tools' );
+const Vinyl = require( 'vinyl' );
+
+describe( 'test-editor', () => {
+	describe( 'skipManual', () => {
+		it( 'should skip manual tests', ( done ) => {
+			const stream = tasks.skipManual();
+			const spy = sinon.spy();
+			const stub = sinon.stub( devTools, '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( buildUtils.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 = buildUtils.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();
+		} );
+	} );
+} );

+ 1 - 0
gulpfile.js

@@ -18,6 +18,7 @@ const config = {
 require( './dev/tasks/build/tasks' )( config );
 require( './dev/tasks/dev/tasks' )( config );
 require( './dev/tasks/lint/tasks' )( config );
+require( './dev/tasks/test/tasks' )( config );
 require( './dev/tasks/docs/tasks' )( config );
 
 gulp.task( 'default', [ 'build' ] );

+ 3 - 0
package.json

@@ -23,6 +23,7 @@
     "babel-core": "^6.4.0",
     "babel-plugin-transform-es2015-modules-amd": "^6.1.18",
     "babel-plugin-transform-es2015-modules-commonjs": "^6.2.0",
+    "babel-plugin-transform-es2015-parameters": "^6.5.0",
     "benderjs": "^0.4.1",
     "benderjs-chai": "^0.2.0",
     "benderjs-coverage": "^0.2.1",
@@ -37,10 +38,12 @@
     "gulp": "^3.9.0",
     "gulp-babel": "^6.1.0",
     "gulp-filter": "^3.0.1",
+    "gulp-filter-by": "^1.2.0",
     "gulp-jscs": "^3.0.2",
     "gulp-jsdoc3": "^0.2.0",
     "gulp-jshint": "^2.0.0",
     "gulp-mirror": "^1",
+    "gulp-mocha": "^2.2.0",
     "gulp-plumber": "^1.1.0",
     "gulp-rename": "^1.2.2",
     "gulp-replace": "^0.5.4",