@@ -11,7 +11,9 @@ import open from 'open';
11
11
import lazypipe from 'lazypipe' ;
12
12
import { stream as wiredep } from 'wiredep' ;
13
13
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 ) { % >
15
17
import nib from 'nib' ; < % } % >
16
18
17
19
var plugins = gulpLoadPlugins ( ) ;
@@ -31,16 +33,8 @@ const paths = {
31
33
mainStyle : `${ clientPath } /app/app.<%= styleExt %>` ,
32
34
views : `${ clientPath } /{app,components}/**/*.<%= templateExt %>` ,
33
35
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' ] ,
44
38
bower : `${ clientPath } /bower_components/`
45
39
} ,
46
40
server : {
@@ -127,6 +121,12 @@ let lintServerScripts = lazypipe()<% if(filters.coffee) { %>
127
121
. pipe ( plugins . jshint , `${ serverPath } /.jshintrc` )
128
122
. pipe ( plugins . jshint . reporter , 'jshint-stylish' ) ; < % } % >
129
123
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
+
130
130
let styles = lazypipe ( )
131
131
. pipe ( plugins . sourcemaps . init ) < % if ( filters . stylus ) { % >
132
132
. pipe ( plugins . stylus , {
@@ -146,6 +146,28 @@ let transpile = lazypipe()
146
146
. pipe ( plugins . coffee , { bare : true } ) < % } % >
147
147
. pipe ( plugins . sourcemaps . write , '.' ) ; < % } % >
148
148
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
+
149
171
/********************
150
172
* Env
151
173
********************/
@@ -256,6 +278,22 @@ gulp.task('lint:scripts:server', () => {
256
278
. pipe ( lintServerScripts ( ) ) ;
257
279
} ) ;
258
280
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
+
259
297
gulp . task ( 'clean:tmp' , ( ) => del ( [ '.tmp/**/*' ] ) ) ;
260
298
261
299
gulp . task ( 'start:client' , cb => {
@@ -265,6 +303,13 @@ gulp.task('start:client', cb => {
265
303
} ) ;
266
304
} ) ;
267
305
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
+
268
313
gulp . task ( 'start:server' , ( ) => {
269
314
process . env . NODE_ENV = process . env . NODE_ENV || 'development' ;
270
315
config = require ( `./${ serverPath } /config/environment` ) ;
@@ -314,6 +359,15 @@ gulp.task('serve', cb => {
314
359
cb);
315
360
} ) ;
316
361
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
+
317
371
gulp . task ( 'test' , cb => {
318
372
return runSequence ( 'test:server' , 'test:client' , cb ) ;
319
373
} ) ;
@@ -323,30 +377,26 @@ gulp.task('test:server', cb => {
323
377
'env:all' ,
324
378
'env:test' ,
325
379
'mocha:unit' ,
380
+ 'mocha:integration' ,
326
381
//'mocha:coverage',
327
382
cb ) ;
328
383
} ) ;
329
384
330
385
gulp . task ( 'mocha:unit' , ( ) => {
331
386
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 ( ) ) ;
341
393
} ) ;
342
394
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 ( ) ;
350
400
} ) ;
351
401
352
402
// inject bower components
@@ -498,3 +548,48 @@ gulp.task('copy:server', () => {
498
548
] , { cwdbase : true } )
499
549
. pipe ( gulp . dest ( paths . dist ) ) ;
500
550
} ) ;
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