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;
|
|
|
|
};
|
2016-10-18 22:35:41 +00:00
|
|
|
let timeoutFunction = function () {
|
2016-03-26 16:22:46 +00:00
|
|
|
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);
|
2016-10-18 22:35:41 +00:00
|
|
|
let stream = gulp.src('./test/*.md')
|
2016-03-26 16:22:46 +00:00
|
|
|
.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-10-18 22:35:41 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7QUFDM0IsSUFBSSxZQUFZLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBQUM7QUFDL0MsSUFBSSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ3JDLElBQUksQ0FBQyxHQUFHLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUVyQixJQUFJLFVBQVUsR0FBRztJQUNiLElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQU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