gulp-function/test/test.js

102 lines
8.2 KiB
JavaScript
Raw Normal View History

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");
2016-10-19 05:36:32 +00:00
const beautylog = require("beautylog");
2016-10-18 23:10:45 +00:00
let Q = require('q');
let myFunction = function () {
let done = Q.defer();
beautylog.log('Function executed');
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');
done.resolve();
return done.promise;
};
2016-10-18 23:10:45 +00:00
let myFunction3 = function () {
let done = Q.defer();
beautylog.success('Function3 executed');
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;
};
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);
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-19 05:36:32 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7QUFDMUIseUNBQXdDO0FBRXhDLHVDQUFzQztBQUN0QyxJQUFJLENBQUMsR0FBRyxPQUFPLENBQUMsR0FBRyxDQUFDLENBQUE7QUFFcEIsSUFBSSxVQUFVLEdBQUc7SUFDYixJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7SUFDcEIsU0FBUyxDQUFDLEdBQUcsQ0FBQyxtQkFBbUIsQ0FBQyxDQUFBO0lBQ2xDLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtJQUNkLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3ZCLENBQUMsQ0FBQTtBQUNELElBQUksV0FBVyxHQUFHO0lBQ2QsSUFBSSxJQUFJLEdBQUcsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO0lBQ3BCLFNBQVMsQ0FBQyxFQUFFLENBQUMsb0JBQW9CLENBQUMsQ0FBQTtJQUNsQyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7SUFDZCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUN2QixDQUFDLENBQUE7QUFDRCxJQUFJLFdBQVcsR0FBRztJQUNkLElBQUksSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUNwQixTQUFTLENBQUMsT0FBTyxDQUFDLG9CQUFvQixDQUFDLENBQUE7SUFDdk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