Skip to content
Snippets Groups Projects
gulpfile.js 2.23 KiB
Newer Older
const gulp   = require('gulp');
const jshint = require('gulp-jshint');
const shell = require('gulp-shell');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');

var js_files = "**/*.js";

const app_state = (process.env.NODE_ENV || 'development').trim().toLowerCase();

//dev config
var dev_config_file = './config.js';

var test_config_file = './config_test.js';
// define the default task and add the watch task to it
gulp.task('default', ['run','watch']);

// configure the jshint task
gulp.task('jshint', function() {
  return gulp.src([js_files, "!node_modules/**/*.js", "!coverage/*"])
    .pipe(jshint({
      "esversion": 6
    }))
    .pipe(jshint.reporter('jshint-stylish'));
});

// configure which files to watch and what tasks to use on file changes
gulp.task('watch', function() {
  gulp.watch(js_files/*, ['jshint']*/);
});

gulp.task('run', function(){
  return gulp.src("*")
    .pipe(shell('npm start'));
});

//Run as a user with CREATE permission and permission to create users on postgresql
gulp.task('create_database_test', function(){

  var config = require(test_config_file);

  return gulp.src("database")
      .pipe(shell("yes | ./database/create_database.sh " + config.db_config.database))
      .pipe(shell("yes | ./database/create_user.sh " + config.db_config.user + " " + config.db_config.password + " " + config.db_config.database ));


gulp.task('pre-test', () => {
    return gulp.src(['src/**/*.js'])
        .pipe(istanbul({includeUntested: true}))
        .pipe(istanbul.hookRequire());
});

gulp.task('test',['create_database_test','pre-test'], function(){

  gulp.src(['test/**/*.js'], {read: false})
    .pipe(mocha({timeout: 60000}))
    .pipe(istanbul.writeReports())
    .pipe(istanbul.enforceThresholds({
        thresholds: {
            global: {
                statements: 80,
                branches: 70,
                lines: 80,
                functions: 80
            }
        }
    }))
    .on('error', () => {
        process.exit(1);
    })
    .on('end', () => {
        process.exit();
    });


  // return gulp.src(['test/*.js'])
  //     .pipe(mocha({
  //       reporter : 'spec'
  //     }));