How to test Gulp tasks

gulp, unit-testing

Solution

A way to reduce complexity may be modularizing tasks and putting them in separate files. In this case you may need to share gulp instance and gulp plugins. I did it this way:

in `Gulpfile.coffee`:

gulp = require 'gulp'
$ = require('gulp-load-plugins')()

require('./src/build/build-task')(gulp, $)

gulp.task "default", ['build']

in `./src/build/build-task.coffee`:

module.exports = (gulp, $)->    
   gulp.task "build",->
       $.util.log "running build task"

Although some may argue that this approach would make it even more complex and it's maybe better to keep everything in Gulpfile, however it worked for me, and it almost feels I can live with no tests now.

Problem

Since I started using Gulp, my project got bigger. Now I have a few quite fancy tasks and now I'm wondering maybe I should build some unit tests to keep some sanity? Is there a good and simple way to load Gulpfile and make sure my tasks are doing what I want them to do? Anybody ever tested their scripts, or it's absolute waste of time?

Original source