gulp-function/test/test.js

101 lines
3.3 KiB
JavaScript
Raw Normal View History

2016-03-26 16:22:46 +00:00
/// <reference path="../ts/typings/main.d.ts" />
2016-02-01 02:33:33 +00:00
var gulp = require("gulp");
2016-03-26 16:22:46 +00:00
var gulpFunction = require("../dist/index.js");
2016-02-01 02:33:33 +00:00
var beautylog = require("beautylog");
var Q = require("q");
2016-02-01 02:33:33 +00:00
var myFunction = function () {
var done = Q.defer();
2016-02-12 04:36:23 +00:00
beautylog.log("Function executed");
done.resolve();
return done.promise;
2016-02-12 04:36:23 +00:00
};
var myFunction2 = function () {
var done = Q.defer();
beautylog.ok("Function2 executed");
done.resolve();
return done.promise;
};
var myFunction3 = function () {
var done = Q.defer();
beautylog.success("Function3 executed");
done.resolve();
return done.promise;
2016-02-01 02:33:33 +00:00
};
2016-03-26 16:22:46 +00:00
var beforeFunction = function () {
var done = Q.defer();
beautylog.success("beforeFunction executed");
done.resolve();
return done.promise;
};
var middleFunctionRun = false;
var middleFunction = function () {
var done = Q.defer();
beautylog.success("middleFunction executed");
setTimeout(function () {
beautylog.log("timeout fired");
middleFunctionRun = true;
done.resolve();
}, 500);
return done.promise;
};
var afterFunction = function () {
var done = Q.defer();
beautylog.success("afterFunction executed");
done.resolve();
return done.promise;
};
var timeoutFunction = function () {
var done = Q.defer();
setTimeout(function () {
beautylog.log("largeTimeout fired");
done.resolve();
}, 2000);
return done.promise;
};
2016-02-01 02:33:33 +00:00
describe("gulpFunction", function () {
it("should run through smoothly with " + "'forEach'".blue, function (done) {
2016-02-12 04:36:23 +00:00
gulp.src('./test/*.md')
.pipe(gulpFunction(myFunction, 'forEach'))
.pipe(gulp.dest("./test/result/"));
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2, myFunction3], 'forEach'))
.pipe(gulp.dest("./test/result/"))
.pipe(gulpFunction(done, "atEnd"));
2016-02-12 04:36:23 +00:00
});
it("should run through smoothly with " + "'atEnd'".blue, function (done) {
2016-02-12 04:36:23 +00:00
gulp.src('./test/*.md')
.pipe(gulpFunction(myFunction, 'atEnd'))
.pipe(gulp.dest("./test/result/"));
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2, myFunction3], 'atEnd'))
.pipe(gulp.dest("./test/result/"))
.pipe(gulpFunction(done, "atEnd"));
2016-02-01 02:33:33 +00:00
});
2016-03-26 16:22:46 +00:00
it("should run through smoothly once with " + "'atFirst'".blue, function (done) {
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2, myFunction3], 'forFirst'))
.pipe(gulp.dest("./test/result/"))
.pipe(gulpFunction(done, "atEnd"));
});
it("should run in order", function (done) {
this.timeout(5000);
var stream = gulp.src('./test/*.md')
.pipe(gulpFunction([beforeFunction, middleFunction, middleFunction], 'atEnd'))
.pipe(gulpFunction(function () {
beautylog.log("stream progressed");
var done2 = Q.defer();
done2.resolve();
return done2.promise;
}, "forEach"))
.pipe(gulpFunction(function () {
beautylog.log("nextStep");
}))
.pipe(gulpFunction(afterFunction, "atEnd"))
.pipe(gulpFunction(timeoutFunction, "atEnd"));
stream.on("finish", function () {
beautylog.info("stream finished");
done();
});
});
2016-02-01 02:33:33 +00:00
});
2016-04-07 11:56:09 +00:00
//# sourceMappingURL=test.js.map