Skip to content

Commit

Permalink
feat(gulp): add missing tasks
Browse files Browse the repository at this point in the history
add the following tasks:
* `lint:scripts:test`
* `lint:scripts:serverTest`
* `coverage:integration`
* `coverage:pre`
* `coverage:unit`
* `jscs`
* `lint:scripts:clientTest`
* `lint:scripts:serverTest`
* `mocha:coverage`
* `mocha:integration`
* `serve:dist`
* `start:server:prod`
* `test:e2e`
* `webdriver_update`
  • Loading branch information
david-mohr committed Dec 18, 2015
1 parent 77b7be6 commit 4d0e2ba
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 27 deletions.
3 changes: 3 additions & 0 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
"gulp-angular-templatecache": "^1.7.0",
"gulp-autoprefixer": "2.3.1",<% if(filters.babel) { %>
"gulp-babel": "^5.1.0",<% } %>
"gulp-babel-istanbul": "^0.11.0",
"gulp-cache": "^0.2.10",
"gulp-concat": "^2.6.0",
"gulp-filter": "^2.0.2",
"gulp-imagemin": "^2.2.1",
"gulp-inject": "^1.3.1",
"gulp-jscs": "^3.0.2",
"gulp-jshint": "^1.11.0",<% if(filters.less) { %>
"gulp-less": "3.0.3",<% } %>
"gulp-livereload": "^3.8.0",
Expand All @@ -58,6 +60,7 @@
"gulp-ng-annotate": "^1.1.0",
"gulp-ng-constant": "^1.1.0",
"gulp-plumber": "^1.0.1",
"gulp-protractor": "^2.1.0",
"gulp-rename": "^1.2.2",
"gulp-rev": "^5.0.0",
"gulp-rev-replace": "^0.4.2",
Expand Down
149 changes: 122 additions & 27 deletions app/templates/gulpfile.babel(gulp).js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import open from 'open';
import lazypipe from 'lazypipe';
import {stream as wiredep} from 'wiredep';
import nodemon from 'nodemon';
import runSequence from 'run-sequence';<% if(filters.stylus) { %>
import {Server as KarmaServer} from 'karma';
import runSequence from 'run-sequence';
import {protractor, webdriver_update} from 'gulp-protractor';<% if(filters.stylus) { %>
import nib from 'nib';<% } %>

var plugins = gulpLoadPlugins();
Expand All @@ -31,16 +33,8 @@ const paths = {
mainStyle: `${clientPath}/app/app.<%= styleExt %>`,
views: `${clientPath}/{app,components}/**/*.<%= templateExt %>`,
mainView: `${clientPath}/index.html`,
test: [`${clientPath}/{app,components}/**/*.spec.<%= scriptExt %>`],
testRequire: [
`${clientPath}/bower_components/angular/angular.js`,
`${clientPath}/bower_components/angular-mocks/angular-mocks.js`,
`${clientPath}/bower_components/angular-resource/angular-resource.js`,
`${clientPath}/bower_components/angular-cookies/angular-cookies.js`,
`${clientPath}/bower_components/angular-sanitize/angular-sanitize.js`,
`${clientPath}/bower_components/angular-route/angular-route.js`,
`${clientPath}/**/*.spec.<%= scriptExt %>`
],
test: [`${clientPath}/{app,components}/**/*.{spec,mock}.<%= scriptExt %>`],
e2e: ['e2e/**/*.spec.js'],
bower: `${clientPath}/bower_components/`
},
server: {
Expand Down Expand Up @@ -127,6 +121,12 @@ let lintServerScripts = lazypipe()<% if(filters.coffee) { %>
.pipe(plugins.jshint, `${serverPath}/.jshintrc`)
.pipe(plugins.jshint.reporter, 'jshint-stylish');<% } %>

let lintServerTestScripts = lazypipe()<% if(filters.coffee) { %>
.pipe(plugins.coffeelint)
.pipe(plugins.coffeelint.reporter);<% } else { %>
.pipe(plugins.jshint, `${serverPath}/.jshintrc-spec`)
.pipe(plugins.jshint.reporter, 'jshint-stylish');<% } %>

let styles = lazypipe()
.pipe(plugins.sourcemaps.init)<% if(filters.stylus) { %>
.pipe(plugins.stylus, {
Expand All @@ -146,6 +146,28 @@ let transpile = lazypipe()
.pipe(plugins.coffee, {bare: true})<% } %>
.pipe(plugins.sourcemaps.write, '.');<% } %>

let mocha = lazypipe()
.pipe(plugins.mocha, {
reporter: 'spec',
timeout: 5000,
require: [
'./mocha.conf'
]
});

let istanbul = lazypipe()
.pipe(plugins.babelIstanbul.writeReports)
.pipe(plugins.babelIstanbul.enforceThresholds, {
thresholds: {
global: {
lines: 80,
statements: 80,
branches: 80,
functions: 80
}
}
});

/********************
* Env
********************/
Expand Down Expand Up @@ -256,6 +278,22 @@ gulp.task('lint:scripts:server', () => {
.pipe(lintServerScripts());
});

gulp.task('lint:scripts:clientTest', () => {
return gulp.src(paths.client.test)
.pipe(lintClientScripts());
});

gulp.task('lint:scripts:serverTest', () => {
return gulp.src(paths.server.test)
.pipe(lintServerTestScripts());
});

gulp.task('jscs', () => {
return gulp.src(_.union(paths.client.scripts, paths.server.scripts))
.pipe(plugins.jscs())
.pipe(plugins.jscs.reporter());
});

gulp.task('clean:tmp', () => del(['.tmp/**/*']));

gulp.task('start:client', cb => {
Expand All @@ -265,6 +303,13 @@ gulp.task('start:client', cb => {
});
});

gulp.task('start:server:prod', () => {
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
config = require(`./${paths.dist}/${serverPath}/config/environment`);
nodemon(`-w ${paths.dist}/${serverPath} ${paths.dist}/${serverPath}`)
.on('log', onServerLog);
});

gulp.task('start:server', () => {
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
config = require(`./${serverPath}/config/environment`);
Expand Down Expand Up @@ -314,6 +359,15 @@ gulp.task('serve', cb => {
cb);
});

gulp.task('serve:dist', cb => {
runSequence(
'build',
'env:all',
'env:prod',
['start:server:prod', 'start:client'],
cb);
});

gulp.task('test', cb => {
return runSequence('test:server', 'test:client', cb);
});
Expand All @@ -323,30 +377,26 @@ gulp.task('test:server', cb => {
'env:all',
'env:test',
'mocha:unit',
'mocha:integration',
//'mocha:coverage',
cb);
});

gulp.task('mocha:unit', () => {
return gulp.src(paths.server.test)
.pipe(plugins.mocha({
reporter: 'spec',
require: [
'./mocha.conf'
]
}))
.once('end', function() {
process.exit();
});
.pipe(mocha());
});

gulp.task('mocha:integration', () => {
return gulp.src(paths.server.test.integration)
.pipe(mocha());
});

gulp.task('test:client', () => {
let testFiles = _.union(paths.client.testRequire, paths.client.test);
return gulp.src(testFiles)
.pipe(plugins.karma({
configFile: paths.karma,
action: 'watch'
}));
gulp.task('test:client', (done) => {
new KarmaServer({
configFile: `${__dirname}/${paths.karma}`,
singleRun: true
}, done).start();
});

// inject bower components
Expand Down Expand Up @@ -498,3 +548,48 @@ gulp.task('copy:server', () => {
], {cwdbase: true})
.pipe(gulp.dest(paths.dist));
});

gulp.task('coverage:pre', () => {
return gulp.src(paths.server.scripts)
// Covering files
.pipe(plugins.babelIstanbul())
// Force `require` to return covered files
.pipe(plugins.babelIstanbul.hookRequire());
});

gulp.task('coverage:unit', () => {
return gulp.src(paths.server.test.unit)
.pipe(mocha())
.pipe(istanbul())
// Creating the reports after tests ran
});

gulp.task('coverage:integration', () => {
return gulp.src(paths.server.test.integration)
.pipe(mocha())
.pipe(istanbul())
// Creating the reports after tests ran
});

gulp.task('mocha:coverage', cb => {
runSequence('coverage:pre',
'env:all',
'env:test',
'coverage:unit',
'coverage:integration',
cb);
});

// Downloads the selenium webdriver
gulp.task('webdriver_update', webdriver_update);

gulp.task('test:e2e', ['env:all', 'env:test', 'start:server', 'webdriver_update'], cb => {
gulp.src(paths.client.e2e)
.pipe(protractor({
configFile: 'protractor.conf.js',
})).on('error', err => {
console.log(err)
}).on('end', () => {
process.exit();
});
});

0 comments on commit 4d0e2ba

Please sign in to comment.