Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 39d7661

Browse files
committedMay 9, 2013
chore(build): Use grunt-karma for testing
1 parent 041261b commit 39d7661

File tree

2 files changed

+30
-46
lines changed

2 files changed

+30
-46
lines changed
 

‎Gruntfile.js

+28-45
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = function(grunt) {
88
grunt.loadNpmTasks('grunt-contrib-jshint');
99
grunt.loadNpmTasks('grunt-contrib-uglify');
1010
grunt.loadNpmTasks('grunt-html2js');
11+
grunt.loadNpmTasks('grunt-karma');
1112

1213
// Project configuration.
1314
grunt.initConfig({
@@ -23,17 +24,15 @@ module.exports = function(grunt) {
2324
tplmodules: 'angular.module("ui.bootstrap.tpls", [<%= tplModules %>]);',
2425
all: 'angular.module("ui.bootstrap", ["ui.bootstrap.tpls", <%= srcModules %>]);'
2526
},
26-
watch: {
27+
delta: {
2728
html: {
2829
files: ['template/**/*.html'],
29-
tasks: ['html2js']
30+
tasks: ['html2js', 'karma:watch:run']
3031
},
3132
js: {
32-
//nospawn makes the tests start faster
33-
nospawn: true,
3433
files: ['src/**/*.js'],
3534
//we don't need to jshint here, it slows down everything else
36-
tasks: ['test-run']
35+
tasks: ['karma:watch:run']
3736
}
3837
},
3938
concat: {
@@ -112,13 +111,34 @@ module.exports = function(grunt) {
112111
angular: true
113112
}
114113
}
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+
}
115129
}
116130
});
117131

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
119134
grunt.registerTask('before-test', ['jshint', 'html2js']);
120135
grunt.registerTask('after-test', ['build', 'copy']);
121136

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+
122142
// Default task.
123143
grunt.registerTask('default', ['before-test', 'test', 'after-test']);
124144

@@ -235,26 +255,8 @@ module.exports = function(grunt) {
235255
grunt.task.run(['concat', 'uglify']);
236256
});
237257

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');
258260
});
259261

260262
//changelog generation
@@ -322,24 +324,5 @@ module.exports = function(grunt) {
322324
});
323325
});
324326

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-
344327
return grunt;
345328
};

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"grunt-contrib-uglify": "~0.2.0",
1212
"grunt-contrib-watch": "~0.3.1",
1313
"grunt-contrib-jshint": "~0.4.0",
14-
"grunt-html2js": "~0.1.3"
14+
"grunt-html2js": "~0.1.3",
15+
"grunt-karma": "~0.4.4"
1516
}
1617
}

0 commit comments

Comments
 (0)