gulp-function/test/test.ts

120 lines
3.2 KiB
TypeScript
Raw Normal View History

2016-10-18 23:10:45 +00:00
import 'typings-test'
2016-10-19 05:36:32 +00:00
let gulp = require('gulp')
2016-10-18 23:10:45 +00:00
import gulpFunction from '../dist/index'
2016-10-19 05:36:32 +00:00
import * as beautylog from 'beautylog'
2016-10-18 23:10:45 +00:00
let Q = require('q')
let myFunction = function () {
let done = Q.defer()
2016-10-19 05:36:32 +00:00
beautylog.log('Function executed')
done.resolve()
return done.promise
}
2016-10-18 23:10:45 +00:00
let myFunction2 = function () {
2016-10-19 05:36:32 +00:00
let done = Q.defer()
beautylog.ok('Function2 executed')
done.resolve()
return done.promise
}
2016-10-18 23:10:45 +00:00
let myFunction3 = function () {
2016-10-19 05:36:32 +00:00
let done = Q.defer()
beautylog.success('Function3 executed')
done.resolve()
return done.promise
}
2016-03-26 16:22:46 +00:00
2016-10-18 23:10:45 +00:00
let beforeFunction = function () {
2016-10-19 05:36:32 +00:00
let done = Q.defer()
beautylog.success('beforeFunction executed')
done.resolve()
return done.promise
}
2016-03-26 16:22:46 +00:00
2016-10-19 05:36:32 +00:00
let middleFunctionRun = false
2016-03-26 16:22:46 +00:00
2016-10-18 23:10:45 +00:00
let middleFunction = function () {
2016-10-19 05:36:32 +00:00
let done = Q.defer()
beautylog.success('middleFunction executed')
2016-03-26 16:22:46 +00:00
setTimeout(function(){
2016-10-19 05:36:32 +00:00
beautylog.log('timeout fired')
middleFunctionRun = true
done.resolve()
}, 500)
return done.promise
}
2016-03-26 16:22:46 +00:00
2016-10-18 23:10:45 +00:00
let afterFunction = function () {
2016-10-19 05:36:32 +00:00
let done = Q.defer()
beautylog.success('afterFunction executed')
done.resolve()
return done.promise
}
2016-03-26 16:22:46 +00:00
let timeoutFunction = function(){
2016-10-19 05:36:32 +00:00
let done = Q.defer()
2016-03-26 16:22:46 +00:00
setTimeout(function(){
2016-10-19 05:36:32 +00:00
beautylog.log('largeTimeout fired')
done.resolve()
},2000)
return done.promise
}
2016-03-26 16:22:46 +00:00
2016-10-18 23:10:45 +00:00
describe('gulpFunction',function(){
it('should run through smoothly with ' + "'forEach'",function(done){
2016-03-26 16:22:46 +00:00
gulp.src('./test/*.md')
.pipe(gulpFunction(myFunction,'forEach'))
2016-10-19 05:36:32 +00:00
.pipe(gulp.dest('./test/result/'))
2016-03-26 16:22:46 +00:00
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2,myFunction3],'forEach'))
2016-10-18 23:10:45 +00:00
.pipe(gulp.dest('./test/result/'))
2016-10-19 05:36:32 +00:00
.pipe(gulpFunction(done,'atEnd'))
2016-03-26 16:22:46 +00:00
2016-10-19 05:36:32 +00:00
})
2016-03-26 16:22:46 +00:00
2016-10-18 23:10:45 +00:00
it('should run through smoothly with ' + "'atEnd'",function(done){
2016-03-26 16:22:46 +00:00
gulp.src('./test/*.md')
.pipe(gulpFunction(myFunction,'atEnd'))
2016-10-19 05:36:32 +00:00
.pipe(gulp.dest('./test/result/'))
2016-03-26 16:22:46 +00:00
gulp.src('./test/*.md')
.pipe(gulpFunction([myFunction2,myFunction3],'atEnd'))
2016-10-18 23:10:45 +00:00
.pipe(gulp.dest('./test/result/'))
2016-10-19 05:36:32 +00:00
.pipe(gulpFunction(done,'atEnd'))
})
2016-03-26 16:22:46 +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')
.pipe(gulpFunction([myFunction2,myFunction3],'forFirst'))
2016-10-18 23:10:45 +00:00
.pipe(gulp.dest('./test/result/'))
2016-10-19 05:36:32 +00:00
.pipe(gulpFunction(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-10-19 05:36:32 +00:00
this.timeout(5000)
2016-03-26 16:22:46 +00:00
let stream = gulp.src('./test/*.md')
.pipe(gulpFunction([beforeFunction,middleFunction,middleFunction],'atEnd'))
.pipe(gulpFunction(function(){
2016-10-19 05:36:32 +00:00
beautylog.log('stream progressed')
let done2 = Q.defer()
done2.resolve()
return done2.promise
2016-10-18 23:10:45 +00:00
},'forEach'))
2016-03-26 16:22:46 +00:00
.pipe(gulpFunction(function(){
2016-10-19 05:36:32 +00:00
beautylog.log('nextStep')
2016-03-26 16:22:46 +00:00
}))
2016-10-18 23:10:45 +00:00
.pipe(gulpFunction(afterFunction,'atEnd'))
2016-10-19 05:36:32 +00:00
.pipe(gulpFunction(timeoutFunction,'atEnd'))
2016-03-26 16:22:46 +00:00
2016-10-18 23:10:45 +00:00
stream.on('finish',function(){
2016-10-19 05:36:32 +00:00
beautylog.info('stream finished')
done()
})
})
})
2016-03-26 16:22:46 +00:00