|
| 1 | +var gulp = require('gulp'); |
| 2 | +var jshint = require('gulp-jshint'); |
| 3 | +var rimraf = require('gulp-rimraf'); |
| 4 | +var env = require('gulp-env'); |
| 5 | +var runSequence = require('run-sequence'); |
| 6 | +var fs = require('fs'); |
| 7 | +var coveralls = require('gulp-coveralls'); |
| 8 | +var istanbul = require('gulp-istanbul'); |
| 9 | +var isparta = require('isparta'); |
| 10 | +var mocha = require('gulp-mocha-co'); |
| 11 | +require('shelljs/global'); |
| 12 | + |
| 13 | +gulp.task('no.onlys', function (callback) { |
| 14 | + exec('find . -path "*/*.spec.js" -type f -exec grep -l "describe.only" {} + \n find . -path "*/*.spec.js" -type f -exec grep -l "it.only" {} +', function (code, output) { // jshint ignore:line |
| 15 | + if (output) return callback(new Error("The following files contain .only in their tests")); |
| 16 | + return callback(); |
| 17 | + }); |
| 18 | +}); |
| 19 | + |
| 20 | + |
| 21 | +gulp.task('lint', ['clean'], function () { |
| 22 | + return gulp.src(['**/*.js', '!**/node_modules/**', '!**/server/migration/**', '!coverage/**/*.js']) |
| 23 | + .pipe(jshint({lookup: true})) |
| 24 | + .pipe(jshint.reporter('default')) |
| 25 | + .pipe(jshint.reporter('fail')); |
| 26 | +}); |
| 27 | + |
| 28 | +gulp.task('set_unit_env_vars', function () { |
| 29 | + env({ |
| 30 | + vars: { |
| 31 | + } |
| 32 | + }); |
| 33 | +}); |
| 34 | + |
| 35 | +gulp.task('unit_pre', function () { |
| 36 | + return gulp.src(['**/*.js', '!**/*.spec.js', '!**/node_modules/**/*.js', '!.debug/**/*.js', '!gulpfile.js', '!coverage/**/*.js']) |
| 37 | + .pipe(istanbul({ // Covering files |
| 38 | + instrumenter: isparta.Instrumenter, |
| 39 | + includeUntested: true |
| 40 | + })) |
| 41 | + .pipe(istanbul.hookRequire()) // Force `require` to return covered files |
| 42 | + .on('finish', function () { |
| 43 | + gulp.src(['**/*.unit.spec.js', '!**/node_modules/**/*.js'], {read: false}) |
| 44 | + .pipe(mocha({reporter: 'spec', timeout: '10000'})) |
| 45 | + .pipe(istanbul.writeReports({ |
| 46 | + reporters: ['lcov'], |
| 47 | + reportOpts: {dir: 'coverage'} |
| 48 | + })) |
| 49 | + .once('end', function () { |
| 50 | + process.exit(); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | + |
| 56 | +gulp.task('set_integ_env_vars', function () { |
| 57 | + env({ |
| 58 | + vars: { |
| 59 | + } |
| 60 | + }); |
| 61 | +}); |
| 62 | + |
| 63 | +gulp.task('integ_pre', function () { |
| 64 | + return gulp.src(['**/*.integ.spec.js', '!**/node_modules/**/*.js'], {read: false}) |
| 65 | + .pipe(mocha({reporter: 'spec', timeout: '10000'})) |
| 66 | + .once('end', function () { |
| 67 | + process.exit(); |
| 68 | + }); |
| 69 | +}); |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +gulp.task('clean', function () { |
| 74 | + return gulp.src(['.coverdata', '.debug', '.coverrun'], {read: false}) |
| 75 | + .pipe(rimraf()); |
| 76 | +}); |
| 77 | + |
| 78 | + |
| 79 | +gulp.task('unit_test', function (callback) { |
| 80 | + runSequence('set_unit_env_vars', |
| 81 | + 'unit_pre', |
| 82 | + callback); |
| 83 | +}); |
| 84 | + |
| 85 | +gulp.task('integ_test', function (callback) { |
| 86 | + runSequence('set_integ_env_vars', |
| 87 | + 'integ_pre', |
| 88 | + callback); |
| 89 | +}); |
| 90 | + |
| 91 | +gulp.task('coveralls', function (callback) { |
| 92 | + var repo_token = process.env.COVERALLS_TOKEN; |
| 93 | + if (!repo_token) { |
| 94 | + return callback(new Error("COVERALLS_TOKEN environment variable is missing")); |
| 95 | + } |
| 96 | + else { |
| 97 | + fs.writeFile(".coveralls.yml", "service_name: codefresh-io\nrepo_token: " + repo_token, function (err) { |
| 98 | + if (err) { |
| 99 | + callback(err); |
| 100 | + } |
| 101 | + else { |
| 102 | + gulp.src('coverage/lcov.info') |
| 103 | + .pipe(coveralls()); |
| 104 | + } |
| 105 | + }); |
| 106 | + } |
| 107 | +}); |
0 commit comments