add better tests and coverage
This commit is contained in:
		
							
								
								
									
										13
									
								
								ts/index.ts
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								ts/index.ts
									
									
									
									
									
								
							@@ -4,20 +4,19 @@ var path = require("path");
 | 
			
		||||
var beautylog = require("beautylog");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) {
 | 
			
		||||
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach') {
 | 
			
		||||
    //important vars
 | 
			
		||||
    var gulpFunction = {
 | 
			
		||||
        executionMode: executionModeArg, //can be forEach or atEnd
 | 
			
		||||
        functionsToExecute: functionsToExecuteArg,
 | 
			
		||||
        logBool: logBoolArg
 | 
			
		||||
        functionsToExecute: functionsToExecuteArg
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    var runFunctionNames = function () {
 | 
			
		||||
        if (typeof gulpFunction.functionsToExecute == "function" ) {
 | 
			
		||||
        if (typeof gulpFunction.functionsToExecute === "function" ) {
 | 
			
		||||
            gulpFunction.functionsToExecute();
 | 
			
		||||
        } else if (Array.isArray(gulpFunction.functionsToExecute)) {
 | 
			
		||||
            for (var anyFunction in gulpFunction.functionsToExecute) {
 | 
			
		||||
                anyFunction();
 | 
			
		||||
                gulpFunction.functionsToExecute[anyFunction]();
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            beautylog.error('gulp-callfunction: something is strange with the given arguments');
 | 
			
		||||
@@ -26,9 +25,7 @@ module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:stri
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    var forEach = function (file, enc, cb) {
 | 
			
		||||
        if (gulpFunction.logBool) beautylog.log(gulpFunction.executionMode);
 | 
			
		||||
        if (gulpFunction.executionMode === 'forEach') {
 | 
			
		||||
            if(gulpFunction.logBool) beautylog.log('is forEach');
 | 
			
		||||
            runFunctionNames();
 | 
			
		||||
        }
 | 
			
		||||
        //tell gulp that we are complete
 | 
			
		||||
@@ -36,7 +33,7 @@ module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:stri
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    var atEnd = function(cb) {
 | 
			
		||||
        if (gulpFunction.executionMode == "atEnd") {
 | 
			
		||||
        if (gulpFunction.executionMode === "atEnd") {
 | 
			
		||||
            runFunctionNames();
 | 
			
		||||
        }
 | 
			
		||||
        cb();
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										29
									
								
								ts/test.ts
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								ts/test.ts
									
									
									
									
									
								
							@@ -4,17 +4,30 @@ var gulpFunction = require("../index.js");
 | 
			
		||||
var beautylog = require("beautylog");
 | 
			
		||||
 | 
			
		||||
var myFunction = function () {
 | 
			
		||||
    beautylog.log("Mocha Test successfull!");
 | 
			
		||||
    beautylog.log("Function executed");
 | 
			
		||||
};
 | 
			
		||||
var myFunction2 = function () {
 | 
			
		||||
    beautylog.log("Function2 executed");
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
describe("gulpFunction",function(){
 | 
			
		||||
    it("should run through smoothly",function(){
 | 
			
		||||
        gulp.task('default',function() {
 | 
			
		||||
            gulp.src('./test/test.md')
 | 
			
		||||
                .pipe(gulpFunction(myFunction,'forEach'))
 | 
			
		||||
                .pipe(gulp.dest("./test/result/"))
 | 
			
		||||
        });
 | 
			
		||||
        gulp.start.apply(gulp, ['default']);
 | 
			
		||||
    it("should run through smoothly with " + "'forEach'".blue,function(){
 | 
			
		||||
        gulp.src('./test/*.md')
 | 
			
		||||
            .pipe(gulpFunction(myFunction,'forEach'))
 | 
			
		||||
            .pipe(gulp.dest("./test/result/"));
 | 
			
		||||
        gulp.src('./test/*.md')
 | 
			
		||||
            .pipe(gulpFunction([myFunction,myFunction2],'forEach'))
 | 
			
		||||
            .pipe(gulp.dest("./test/result/"));
 | 
			
		||||
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it("should run through smoothly with " + "'atEnd'".blue,function(){
 | 
			
		||||
        gulp.src('./test/*.md')
 | 
			
		||||
            .pipe(gulpFunction(myFunction,'atEnd'))
 | 
			
		||||
            .pipe(gulp.dest("./test/result/"));
 | 
			
		||||
        gulp.src('./test/*.md')
 | 
			
		||||
            .pipe(gulpFunction([myFunction,myFunction2],'atEnd'))
 | 
			
		||||
            .pipe(gulp.dest("./test/result/"));
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user