@@ -8,6 +8,7 @@ module.exports = function(grunt) {
8
8
grunt . loadNpmTasks ( 'grunt-contrib-jshint' ) ;
9
9
grunt . loadNpmTasks ( 'grunt-contrib-uglify' ) ;
10
10
grunt . loadNpmTasks ( 'grunt-html2js' ) ;
11
+ grunt . loadNpmTasks ( 'grunt-karma' ) ;
11
12
12
13
// Project configuration.
13
14
grunt . initConfig ( {
@@ -23,17 +24,15 @@ module.exports = function(grunt) {
23
24
tplmodules : 'angular.module("ui.bootstrap.tpls", [<%= tplModules %>]);' ,
24
25
all : 'angular.module("ui.bootstrap", ["ui.bootstrap.tpls", <%= srcModules %>]);'
25
26
} ,
26
- watch : {
27
+ delta : {
27
28
html : {
28
29
files : [ 'template/**/*.html' ] ,
29
- tasks : [ 'html2js' ]
30
+ tasks : [ 'html2js' , 'karma:watch:run' ]
30
31
} ,
31
32
js : {
32
- //nospawn makes the tests start faster
33
- nospawn : true ,
34
33
files : [ 'src/**/*.js' ] ,
35
34
//we don't need to jshint here, it slows down everything else
36
- tasks : [ 'test- run' ]
35
+ tasks : [ 'karma:watch: run' ]
37
36
}
38
37
} ,
39
38
concat : {
@@ -112,13 +111,34 @@ module.exports = function(grunt) {
112
111
angular : true
113
112
}
114
113
}
114
+ } ,
115
+ karma : {
116
+ options : {
117
+ configFile : 'karma.conf.js'
118
+ } ,
119
+ watch : {
120
+ background : true
121
+ } ,
122
+ continuous : {
123
+ singleRun : true
124
+ } ,
125
+ travis : {
126
+ singleRun : true ,
127
+ browsers : [ 'Firefox' ]
128
+ }
115
129
}
116
130
} ) ;
117
131
118
- //register before and after test tasks so we've don't have to change cli options on the goole's CI server
132
+ //register before and after test tasks so we've don't have to change cli
133
+ //options on the goole's CI server
119
134
grunt . registerTask ( 'before-test' , [ 'jshint' , 'html2js' ] ) ;
120
135
grunt . registerTask ( 'after-test' , [ 'build' , 'copy' ] ) ;
121
136
137
+ //Rename our watch task to 'delta', then make actual 'watch'
138
+ //task build things, then start test server
139
+ grunt . renameTask ( 'watch' , 'delta' ) ;
140
+ grunt . registerTask ( 'watch' , [ 'before-test' , 'after-test' , 'karma:watch' , 'delta' ] ) ;
141
+
122
142
// Default task.
123
143
grunt . registerTask ( 'default' , [ 'before-test' , 'test' , 'after-test' ] ) ;
124
144
@@ -235,26 +255,8 @@ module.exports = function(grunt) {
235
255
grunt . task . run ( [ 'concat' , 'uglify' ] ) ;
236
256
} ) ;
237
257
238
- grunt . registerTask ( 'test' , 'run tests on single-run server' , function ( ) {
239
- var options = [ '--single-run' , '--no-auto-watch' , '--log-level=warn' ]
240
- . concat ( this . args ) //Let user augment test args with command line args
241
- . concat ( process . env . TRAVIS ? '--browsers=Firefox' : '' ) ;
242
- runKarma ( 'start' , options ) ;
243
- } ) ;
244
-
245
- grunt . registerTask ( 'server' , 'start karma server' , function ( ) {
246
- var options = [ '--no-single-run' , '--no-auto-watch' ] . concat ( this . args ) ;
247
- runKarma ( 'start' , options ) ;
248
- } ) ;
249
-
250
- grunt . registerTask ( 'test-run' , 'run tests against continuous karma server' , function ( ) {
251
- var options = [ '--single-run' , '--no-auto-watch' ] . concat ( this . args ) ;
252
- runKarma ( 'run' , options ) ;
253
- } ) ;
254
-
255
- grunt . registerTask ( 'test-watch' , 'start karma server, watch & execute tests' , function ( ) {
256
- var options = [ '--no-single-run' , '--auto-watch' ] . concat ( this . args ) ;
257
- runKarma ( 'start' , options ) ;
258
+ grunt . registerTask ( 'test' , 'Run tests on singleRun karma server' , function ( ) {
259
+ grunt . task . run ( process . env . TRAVIS ? 'karma:travis' : 'karma:continuous' ) ;
258
260
} ) ;
259
261
260
262
//changelog generation
@@ -322,24 +324,5 @@ module.exports = function(grunt) {
322
324
} ) ;
323
325
} ) ;
324
326
325
- // Karma configuration
326
- function runKarma ( command , options ) {
327
- var karmaCmd = process . platform === 'win32' ? 'karma.cmd' : 'karma' ;
328
- var args = [ command ] . concat ( options ) ;
329
- var done = grunt . task . current . async ( ) ;
330
- var child = grunt . util . spawn ( {
331
- cmd : karmaCmd ,
332
- args : args
333
- } , function ( err , result , code ) {
334
- if ( code ) {
335
- done ( false ) ;
336
- } else {
337
- done ( ) ;
338
- }
339
- } ) ;
340
- child . stdout . pipe ( process . stdout ) ;
341
- child . stderr . pipe ( process . stderr ) ;
342
- }
343
-
344
327
return grunt ;
345
328
} ;
0 commit comments