Last active
September 25, 2015 13:29
-
-
Save rdooh/2a1d73978a5ff42ecc0d to your computer and use it in GitHub Desktop.
Simple Gulpfile that implements Jest. Context is a small Express app written in Coffeescript. The coffeescript is transpiled to JS, and then Jest is run on the result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var coffee = require('gulp-coffee'); | |
var header = require('gulp-header'); | |
var pkg = require('./package.json'); | |
var info = '//===========================\n// <%= pkg.name %>\n// @v<%= pkg.version %>, <%= pkg.license %>\n// <%= pkg.author %>\n//===========================\n'; | |
var jest = require('jest-cli'); | |
var gutil = require('gulp-util'); | |
var through = require('through2'); | |
// Simple setup without watchers - use 'watch' instead if needed | |
gulp.task('default', ['jest']); | |
// Run unit tests with jest after a full compile - outputs to a coverage directory | |
gulp.task('jest', ['compile'], function () { | |
return gulp.src(['build']) | |
.pipe( | |
through.obj(function (file, enc, cb) { | |
options = { | |
testDirectoryName: "__tests__", | |
testPathIgnorePatterns: [ | |
"node_modules", | |
"src" | |
], | |
collectCoverage: true, | |
verbose: true, | |
moduleFileExtensions: [ | |
"js" | |
] | |
}; | |
options.rootDir = options.rootDir || file.path; | |
jest.runCLI({ | |
config: options | |
}, options.rootDir, function (success) { | |
if(!success) { | |
cb(new gutil.PluginError('gulp-jest', { message: "Tests Failed" })); | |
} else { | |
cb(); | |
} | |
}.bind(this)); | |
}) | |
); | |
}); | |
// Compiling regular code | |
gulp.task('compile', function(){ | |
return gulp.src(['src/**/*.coffee']) | |
.pipe(coffee({bare: true})) | |
.pipe(header(info, { pkg : pkg })) | |
.pipe(gulp.dest('build')); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment