2016-06-03 23:14:25 +00:00
|
|
|
"use strict";
|
|
|
|
require("typings-test");
|
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");
|
2016-02-14 17:36:34 +00:00
|
|
|
var Q = require("q");
|
2016-02-01 02:33:33 +00:00
|
|
|
var myFunction = function () {
|
2016-02-14 17:36:34 +00:00
|
|
|
var done = Q.defer();
|
2016-02-12 04:36:23 +00:00
|
|
|
beautylog.log("Function executed");
|
2016-02-14 17:36:34 +00:00
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
2016-02-12 04:36:23 +00:00
|
|
|
};
|
|
|
|
var myFunction2 = function () {
|
2016-02-14 17:36:34 +00:00
|
|
|
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 () {
|
2016-02-14 17:36:34 +00:00
|
|
|
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')
|
2016-02-14 17:36:34 +00:00
|
|
|
.pipe(gulpFunction([myFunction2, myFunction3], 'forEach'))
|
|
|
|
.pipe(gulp.dest("./test/result/"))
|
|
|
|
.pipe(gulpFunction(done, "atEnd"));
|
2016-02-12 04:36:23 +00:00
|
|
|
});
|
2016-02-14 17:36:34 +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')
|
2016-02-14 17:36:34 +00:00
|
|
|
.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-06-03 23:14:25 +00:00
|
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FDUCxDQUFDLENBRG9CO0FBQ3JCLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztBQUMzQixJQUFJLFlBQVksR0FBRyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQztBQUMvQyxJQUFJLFNBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDckMsSUFBSSxDQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBRXJCLElBQUksVUFBVSxHQUFHO0lBQ2IsSUFBSSxJQUFJLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO0lBQ3BCLFNBQVMsQ0FBQyxHQUFHLENBQUMsbUJBQW1CLENBQUMsQ0FBQztJQUNu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