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

Commit

Permalink
chore(build): Use grunt-karma for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed May 9, 2013
1 parent 041261b commit 39d7661
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
73 changes: 28 additions & 45 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-html2js');
grunt.loadNpmTasks('grunt-karma');

// Project configuration.
grunt.initConfig({
Expand All @@ -23,17 +24,15 @@ module.exports = function(grunt) {
tplmodules: 'angular.module("ui.bootstrap.tpls", [<%= tplModules %>]);',
all: 'angular.module("ui.bootstrap", ["ui.bootstrap.tpls", <%= srcModules %>]);'
},
watch: {
delta: {
html: {
files: ['template/**/*.html'],
tasks: ['html2js']
tasks: ['html2js', 'karma:watch:run']
},
js: {
//nospawn makes the tests start faster
nospawn: true,
files: ['src/**/*.js'],
//we don't need to jshint here, it slows down everything else
tasks: ['test-run']
tasks: ['karma:watch:run']
}
},
concat: {
Expand Down Expand Up @@ -112,13 +111,34 @@ module.exports = function(grunt) {
angular: true
}
}
},
karma: {
options: {
configFile: 'karma.conf.js'
},
watch: {
background: true
},
continuous: {
singleRun: true
},
travis: {
singleRun: true,
browsers: ['Firefox']
}
}
});

//register before and after test tasks so we've don't have to change cli options on the goole's CI server
//register before and after test tasks so we've don't have to change cli
//options on the goole's CI server
grunt.registerTask('before-test', ['jshint', 'html2js']);
grunt.registerTask('after-test', ['build', 'copy']);

//Rename our watch task to 'delta', then make actual 'watch'
//task build things, then start test server
grunt.renameTask('watch', 'delta');
grunt.registerTask('watch', ['before-test', 'after-test', 'karma:watch', 'delta']);

// Default task.
grunt.registerTask('default', ['before-test', 'test', 'after-test']);

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

grunt.registerTask('test', 'run tests on single-run server', function() {
var options = ['--single-run', '--no-auto-watch', '--log-level=warn']
.concat(this.args) //Let user augment test args with command line args
.concat(process.env.TRAVIS ? '--browsers=Firefox' : '');
runKarma('start', options);
});

grunt.registerTask('server', 'start karma server', function() {
var options = ['--no-single-run', '--no-auto-watch'].concat(this.args);
runKarma('start', options);
});

grunt.registerTask('test-run', 'run tests against continuous karma server', function() {
var options = ['--single-run', '--no-auto-watch'].concat(this.args);
runKarma('run', options);
});

grunt.registerTask('test-watch', 'start karma server, watch & execute tests', function() {
var options = ['--no-single-run', '--auto-watch'].concat(this.args);
runKarma('start', options);
grunt.registerTask('test', 'Run tests on singleRun karma server', function() {
grunt.task.run(process.env.TRAVIS ? 'karma:travis' : 'karma:continuous');
});

//changelog generation
Expand Down Expand Up @@ -322,24 +324,5 @@ module.exports = function(grunt) {
});
});

// Karma configuration
function runKarma(command, options) {
var karmaCmd = process.platform === 'win32' ? 'karma.cmd' : 'karma';
var args = [command].concat(options);
var done = grunt.task.current.async();
var child = grunt.util.spawn({
cmd: karmaCmd,
args: args
}, function(err, result, code) {
if (code) {
done(false);
} else {
done();
}
});
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
}

return grunt;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-watch": "~0.3.1",
"grunt-contrib-jshint": "~0.4.0",
"grunt-html2js": "~0.1.3"
"grunt-html2js": "~0.1.3",
"grunt-karma": "~0.4.4"
}
}

0 comments on commit 39d7661

Please sign in to comment.