Skip to content

Commit 4d0e2ba

Browse files
committed
feat(gulp): add missing tasks
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`
1 parent 77b7be6 commit 4d0e2ba

File tree

2 files changed

+125
-27
lines changed

2 files changed

+125
-27
lines changed

Diff for: app/templates/_package.json

+3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@
4444
"gulp-angular-templatecache": "^1.7.0",
4545
"gulp-autoprefixer": "2.3.1",<% if(filters.babel) { %>
4646
"gulp-babel": "^5.1.0",<% } %>
47+
"gulp-babel-istanbul": "^0.11.0",
4748
"gulp-cache": "^0.2.10",
4849
"gulp-concat": "^2.6.0",
4950
"gulp-filter": "^2.0.2",
5051
"gulp-imagemin": "^2.2.1",
5152
"gulp-inject": "^1.3.1",
53+
"gulp-jscs": "^3.0.2",
5254
"gulp-jshint": "^1.11.0",<% if(filters.less) { %>
5355
"gulp-less": "3.0.3",<% } %>
5456
"gulp-livereload": "^3.8.0",
@@ -58,6 +60,7 @@
5860
"gulp-ng-annotate": "^1.1.0",
5961
"gulp-ng-constant": "^1.1.0",
6062
"gulp-plumber": "^1.0.1",
63+
"gulp-protractor": "^2.1.0",
6164
"gulp-rename": "^1.2.2",
6265
"gulp-rev": "^5.0.0",
6366
"gulp-rev-replace": "^0.4.2",

Diff for: app/templates/gulpfile.babel(gulp).js

+122-27
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import open from 'open';
1111
import lazypipe from 'lazypipe';
1212
import {stream as wiredep} from 'wiredep';
1313
import nodemon from 'nodemon';
14-
import runSequence from 'run-sequence';<% if(filters.stylus) { %>
14+
import {Server as KarmaServer} from 'karma';
15+
import runSequence from 'run-sequence';
16+
import {protractor, webdriver_update} from 'gulp-protractor';<% if(filters.stylus) { %>
1517
import nib from 'nib';<% } %>
1618

1719
var plugins = gulpLoadPlugins();
@@ -31,16 +33,8 @@ const paths = {
3133
mainStyle: `${clientPath}/app/app.<%= styleExt %>`,
3234
views: `${clientPath}/{app,components}/**/*.<%= templateExt %>`,
3335
mainView: `${clientPath}/index.html`,
34-
test: [`${clientPath}/{app,components}/**/*.spec.<%= scriptExt %>`],
35-
testRequire: [
36-
`${clientPath}/bower_components/angular/angular.js`,
37-
`${clientPath}/bower_components/angular-mocks/angular-mocks.js`,
38-
`${clientPath}/bower_components/angular-resource/angular-resource.js`,
39-
`${clientPath}/bower_components/angular-cookies/angular-cookies.js`,
40-
`${clientPath}/bower_components/angular-sanitize/angular-sanitize.js`,
41-
`${clientPath}/bower_components/angular-route/angular-route.js`,
42-
`${clientPath}/**/*.spec.<%= scriptExt %>`
43-
],
36+
test: [`${clientPath}/{app,components}/**/*.{spec,mock}.<%= scriptExt %>`],
37+
e2e: ['e2e/**/*.spec.js'],
4438
bower: `${clientPath}/bower_components/`
4539
},
4640
server: {
@@ -127,6 +121,12 @@ let lintServerScripts = lazypipe()<% if(filters.coffee) { %>
127121
.pipe(plugins.jshint, `${serverPath}/.jshintrc`)
128122
.pipe(plugins.jshint.reporter, 'jshint-stylish');<% } %>
129123

124+
let lintServerTestScripts = lazypipe()<% if(filters.coffee) { %>
125+
.pipe(plugins.coffeelint)
126+
.pipe(plugins.coffeelint.reporter);<% } else { %>
127+
.pipe(plugins.jshint, `${serverPath}/.jshintrc-spec`)
128+
.pipe(plugins.jshint.reporter, 'jshint-stylish');<% } %>
129+
130130
let styles = lazypipe()
131131
.pipe(plugins.sourcemaps.init)<% if(filters.stylus) { %>
132132
.pipe(plugins.stylus, {
@@ -146,6 +146,28 @@ let transpile = lazypipe()
146146
.pipe(plugins.coffee, {bare: true})<% } %>
147147
.pipe(plugins.sourcemaps.write, '.');<% } %>
148148

149+
let mocha = lazypipe()
150+
.pipe(plugins.mocha, {
151+
reporter: 'spec',
152+
timeout: 5000,
153+
require: [
154+
'./mocha.conf'
155+
]
156+
});
157+
158+
let istanbul = lazypipe()
159+
.pipe(plugins.babelIstanbul.writeReports)
160+
.pipe(plugins.babelIstanbul.enforceThresholds, {
161+
thresholds: {
162+
global: {
163+
lines: 80,
164+
statements: 80,
165+
branches: 80,
166+
functions: 80
167+
}
168+
}
169+
});
170+
149171
/********************
150172
* Env
151173
********************/
@@ -256,6 +278,22 @@ gulp.task('lint:scripts:server', () => {
256278
.pipe(lintServerScripts());
257279
});
258280

281+
gulp.task('lint:scripts:clientTest', () => {
282+
return gulp.src(paths.client.test)
283+
.pipe(lintClientScripts());
284+
});
285+
286+
gulp.task('lint:scripts:serverTest', () => {
287+
return gulp.src(paths.server.test)
288+
.pipe(lintServerTestScripts());
289+
});
290+
291+
gulp.task('jscs', () => {
292+
return gulp.src(_.union(paths.client.scripts, paths.server.scripts))
293+
.pipe(plugins.jscs())
294+
.pipe(plugins.jscs.reporter());
295+
});
296+
259297
gulp.task('clean:tmp', () => del(['.tmp/**/*']));
260298

261299
gulp.task('start:client', cb => {
@@ -265,6 +303,13 @@ gulp.task('start:client', cb => {
265303
});
266304
});
267305

306+
gulp.task('start:server:prod', () => {
307+
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
308+
config = require(`./${paths.dist}/${serverPath}/config/environment`);
309+
nodemon(`-w ${paths.dist}/${serverPath} ${paths.dist}/${serverPath}`)
310+
.on('log', onServerLog);
311+
});
312+
268313
gulp.task('start:server', () => {
269314
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
270315
config = require(`./${serverPath}/config/environment`);
@@ -314,6 +359,15 @@ gulp.task('serve', cb => {
314359
cb);
315360
});
316361

362+
gulp.task('serve:dist', cb => {
363+
runSequence(
364+
'build',
365+
'env:all',
366+
'env:prod',
367+
['start:server:prod', 'start:client'],
368+
cb);
369+
});
370+
317371
gulp.task('test', cb => {
318372
return runSequence('test:server', 'test:client', cb);
319373
});
@@ -323,30 +377,26 @@ gulp.task('test:server', cb => {
323377
'env:all',
324378
'env:test',
325379
'mocha:unit',
380+
'mocha:integration',
326381
//'mocha:coverage',
327382
cb);
328383
});
329384

330385
gulp.task('mocha:unit', () => {
331386
return gulp.src(paths.server.test)
332-
.pipe(plugins.mocha({
333-
reporter: 'spec',
334-
require: [
335-
'./mocha.conf'
336-
]
337-
}))
338-
.once('end', function() {
339-
process.exit();
340-
});
387+
.pipe(mocha());
388+
});
389+
390+
gulp.task('mocha:integration', () => {
391+
return gulp.src(paths.server.test.integration)
392+
.pipe(mocha());
341393
});
342394

343-
gulp.task('test:client', () => {
344-
let testFiles = _.union(paths.client.testRequire, paths.client.test);
345-
return gulp.src(testFiles)
346-
.pipe(plugins.karma({
347-
configFile: paths.karma,
348-
action: 'watch'
349-
}));
395+
gulp.task('test:client', (done) => {
396+
new KarmaServer({
397+
configFile: `${__dirname}/${paths.karma}`,
398+
singleRun: true
399+
}, done).start();
350400
});
351401

352402
// inject bower components
@@ -498,3 +548,48 @@ gulp.task('copy:server', () => {
498548
], {cwdbase: true})
499549
.pipe(gulp.dest(paths.dist));
500550
});
551+
552+
gulp.task('coverage:pre', () => {
553+
return gulp.src(paths.server.scripts)
554+
// Covering files
555+
.pipe(plugins.babelIstanbul())
556+
// Force `require` to return covered files
557+
.pipe(plugins.babelIstanbul.hookRequire());
558+
});
559+
560+
gulp.task('coverage:unit', () => {
561+
return gulp.src(paths.server.test.unit)
562+
.pipe(mocha())
563+
.pipe(istanbul())
564+
// Creating the reports after tests ran
565+
});
566+
567+
gulp.task('coverage:integration', () => {
568+
return gulp.src(paths.server.test.integration)
569+
.pipe(mocha())
570+
.pipe(istanbul())
571+
// Creating the reports after tests ran
572+
});
573+
574+
gulp.task('mocha:coverage', cb => {
575+
runSequence('coverage:pre',
576+
'env:all',
577+
'env:test',
578+
'coverage:unit',
579+
'coverage:integration',
580+
cb);
581+
});
582+
583+
// Downloads the selenium webdriver
584+
gulp.task('webdriver_update', webdriver_update);
585+
586+
gulp.task('test:e2e', ['env:all', 'env:test', 'start:server', 'webdriver_update'], cb => {
587+
gulp.src(paths.client.e2e)
588+
.pipe(protractor({
589+
configFile: 'protractor.conf.js',
590+
})).on('error', err => {
591+
console.log(err)
592+
}).on('end', () => {
593+
process.exit();
594+
});
595+
});

0 commit comments

Comments
 (0)