2016-06-03 23:14:25 +00:00
|
|
|
"use strict";
|
|
|
|
require("typings-test");
|
2016-10-18 23:10:45 +00:00
|
|
|
let gulp = require('gulp');
|
|
|
|
const index_1 = require("../dist/index");
|
|
|
|
let beautylog = require('beautylog');
|
|
|
|
let Q = require('q');
|
|
|
|
let myFunction = function () {
|
|
|
|
let done = Q.defer();
|
|
|
|
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
|
|
|
};
|
2016-10-18 23:10:45 +00:00
|
|
|
let myFunction2 = function () {
|
|
|
|
let done = Q.defer();
|
|
|
|
beautylog.ok('Function2 executed');
|
2016-02-14 17:36:34 +00:00
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-10-18 23:10:45 +00:00
|
|
|
let myFunction3 = function () {
|
|
|
|
let done = Q.defer();
|
|
|
|
beautylog.success('Function3 executed');
|
2016-02-14 17:36:34 +00:00
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
2016-02-01 02:33:33 +00:00
|
|
|
};
|
2016-10-18 23:10:45 +00:00
|
|
|
let beforeFunction = function () {
|
|
|
|
let done = Q.defer();
|
|
|
|
beautylog.success('beforeFunction executed');
|
2016-03-26 16:22:46 +00:00
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-10-18 23:10:45 +00:00
|
|
|
let middleFunctionRun = false;
|
|
|
|
let middleFunction = function () {
|
|
|
|
let done = Q.defer();
|
|
|
|
beautylog.success('middleFunction executed');
|
2016-03-26 16:22:46 +00:00
|
|
|
setTimeout(function () {
|
2016-10-18 23:10:45 +00:00
|
|
|
beautylog.log('timeout fired');
|
2016-03-26 16:22:46 +00:00
|
|
|
middleFunctionRun = true;
|
|
|
|
done.resolve();
|
|
|
|
}, 500);
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-10-18 23:10:45 +00:00
|
|
|
let afterFunction = function () {
|
|
|
|
let done = Q.defer();
|
|
|
|
beautylog.success('afterFunction executed');
|
2016-03-26 16:22:46 +00:00
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-10-18 22:35:41 +00:00
|
|
|
let timeoutFunction = function () {
|
2016-10-18 23:10:45 +00:00
|
|
|
let done = Q.defer();
|
2016-03-26 16:22:46 +00:00
|
|
|
setTimeout(function () {
|
2016-10-18 23:10:45 +00:00
|
|
|
beautylog.log('largeTimeout fired');
|
2016-03-26 16:22:46 +00:00
|
|
|
done.resolve();
|
|
|
|
}, 2000);
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-10-18 23:10:45 +00:00
|
|
|
describe('gulpFunction', function () {
|
|
|
|
it('should run through smoothly with ' + "'forEach'", function (done) {
|
2016-02-12 04:36:23 +00:00
|
|
|
gulp.src('./test/*.md')
|
2016-10-18 23:10:45 +00:00
|
|
|
.pipe(index_1.default(myFunction, 'forEach'))
|
|
|
|
.pipe(gulp.dest('./test/result/'));
|
2016-02-12 04:36:23 +00:00
|
|
|
gulp.src('./test/*.md')
|
2016-10-18 23:10:45 +00:00
|
|
|
.pipe(index_1.default([myFunction2, myFunction3], 'forEach'))
|
|
|
|
.pipe(gulp.dest('./test/result/'))
|
|
|
|
.pipe(index_1.default(done, 'atEnd'));
|
2016-02-12 04:36:23 +00:00
|
|
|
});
|
2016-10-18 23:10:45 +00:00
|
|
|
it('should run through smoothly with ' + "'atEnd'", function (done) {
|
2016-02-12 04:36:23 +00:00
|
|
|
gulp.src('./test/*.md')
|
2016-10-18 23:10:45 +00:00
|
|
|
.pipe(index_1.default(myFunction, 'atEnd'))
|
|
|
|
.pipe(gulp.dest('./test/result/'));
|
2016-02-12 04:36:23 +00:00
|
|
|
gulp.src('./test/*.md')
|
2016-10-18 23:10:45 +00:00
|
|
|
.pipe(index_1.default([myFunction2, myFunction3], 'atEnd'))
|
|
|
|
.pipe(gulp.dest('./test/result/'))
|
|
|
|
.pipe(index_1.default(done, 'atEnd'));
|
2016-02-01 02:33:33 +00:00
|
|
|
});
|
2016-10-18 23:10:45 +00:00
|
|
|
it('should run through smoothly once with ' + "'atFirst'", function (done) {
|
2016-03-26 16:22:46 +00:00
|
|
|
gulp.src('./test/*.md')
|
2016-10-18 23:10:45 +00:00
|
|
|
.pipe(index_1.default([myFunction2, myFunction3], 'forFirst'))
|
|
|
|
.pipe(gulp.dest('./test/result/'))
|
|
|
|
.pipe(index_1.default(done, 'atEnd'));
|
2016-03-26 16:22:46 +00:00
|
|
|
});
|
2016-10-18 23:10:45 +00:00
|
|
|
it('should run in order', function (done) {
|
2016-03-26 16:22:46 +00:00
|
|
|
this.timeout(5000);
|
2016-10-18 22:35:41 +00:00
|
|
|
let stream = gulp.src('./test/*.md')
|
2016-10-18 23:10:45 +00:00
|
|
|
.pipe(index_1.default([beforeFunction, middleFunction, middleFunction], 'atEnd'))
|
|
|
|
.pipe(index_1.default(function () {
|
|
|
|
beautylog.log('stream progressed');
|
|
|
|
let done2 = Q.defer();
|
2016-03-26 16:22:46 +00:00
|
|
|
done2.resolve();
|
|
|
|
return done2.promise;
|
2016-10-18 23:10:45 +00:00
|
|
|
}, 'forEach'))
|
|
|
|
.pipe(index_1.default(function () {
|
|
|
|
beautylog.log('nextStep');
|
2016-03-26 16:22:46 +00:00
|
|
|
}))
|
2016-10-18 23:10:45 +00:00
|
|
|
.pipe(index_1.default(afterFunction, 'atEnd'))
|
|
|
|
.pipe(index_1.default(timeoutFunction, 'atEnd'));
|
|
|
|
stream.on('finish', function () {
|
|
|
|
beautylog.info('stream finished');
|
2016-03-26 16:22:46 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-02-01 02:33:33 +00:00
|
|
|
});
|
2016-10-18 23:10:45 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdL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