浏览代码

Added tests to builder build() method.

Szymon Kupś 10 年之前
父节点
当前提交
7c29a28b76
共有 2 个文件被更改,包括 91 次插入0 次删除
  1. 89 0
      dev/tests/build/tasks.js
  2. 2 0
      package.json

+ 89 - 0
dev/tests/build/tasks.js

@@ -0,0 +1,89 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global describe, it, beforeEach, afterEach */
+
+'use strict';
+
+const mockery = require( 'mockery' );
+const sinon = require( 'sinon' );
+const Vinyl = require( 'vinyl' );
+const utils = require( '../../tasks/gulp/build/utils' );
+const babel = require( 'babel-core' );
+const chai = require( 'chai' );
+const expect = chai.expect;
+const gutil = require( 'gulp-util' );
+
+describe( 'build-tasks', () => {
+	let sandbox;
+	const config = {
+		ROOT_DIR: '.',
+		DIST_DIR: 'dist'
+	};
+
+	beforeEach( () => {
+		mockery.enable( {
+			warnOnReplace: false,
+			warnOnUnregistered: false
+		} );
+
+		sandbox = sinon.sandbox.create();
+	} );
+
+	afterEach( () => {
+		mockery.disable();
+		sandbox.restore();
+	} );
+
+	describe( 'build', () => {
+		it( 'should return build stream', ( done ) => {
+			const code = 'export default {};';
+			sandbox.stub( gutil, 'log' );
+			mockery.registerMock( 'minimist', () => {
+				return {
+					formats: 'amd',
+					watch: false
+				};
+			} );
+
+			const tasks = require( '../../tasks/gulp/build/tasks' )( config );
+			const build = tasks.build;
+			const stream = require( 'stream' );
+			const files = [
+				new Vinyl( {
+					cwd: './',
+					path: './src/file.js',
+					contents: new Buffer( code )
+				} )
+			];
+
+			// Stub input stream.
+			sandbox.stub( tasks.src, 'all', () => {
+				const fakeInputStream = new stream.Readable( { objectMode: true } );
+				fakeInputStream._read = () => {
+					fakeInputStream.push( files.pop() || null );
+				};
+
+				return fakeInputStream;
+			} );
+
+			// Stub output stream.
+			sandbox.stub( utils, 'dist', () => {
+				const fakeOutputStream = new stream.Writable( { objectMode: true } );
+				fakeOutputStream._write = ( file, encoding, done ) => {
+					const result = babel.transform( code, { plugins: [ 'transform-es2015-modules-amd' ] } );
+					// Check if provided code was transformed by babel.
+					expect( file.contents.toString() ).to.equal( result.code );
+					done();
+				};
+
+				return fakeOutputStream;
+			} );
+
+			const conversionStream = build();
+			conversionStream.on( 'finish', () => done() );
+		} );
+	} );
+} );

+ 2 - 0
package.json

@@ -13,6 +13,7 @@
   },
   "devDependencies": {
     "almond": "^0.3.0",
+    "babel-core": "^6.4.0",
     "babel-plugin-transform-es2015-modules-amd": "^6.1.18",
     "babel-plugin-transform-es2015-modules-commonjs": "^6.2.0",
     "benderjs": "^0.4.1",
@@ -40,6 +41,7 @@
     "merge-stream": "^1.0.0",
     "minimist": "^1.2.0",
     "mocha": "^2.2.5",
+    "mockery": "^1.4.0",
     "multipipe": "^0.2.1",
     "ncp": "^2.0.0",
     "replace": "^0.3.0",