Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created October 28, 2012 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaskills/3968623 to your computer and use it in GitHub Desktop.
Save metaskills/3968623 to your computer and use it in GitHub Desktop.
Example Grunt.js Watch To Run Cakefile Tests
/*
An example grunt.js file to watch all my coffeescript files, then run `cake test`
on changes. My Cakefile is setup to run run tests for different DOM libraries using
tasks name like `test:jquery18` and `test:zepto10`, so the grunt multi task example
below will parse these from the tasks `this.nameArgs`.
*/
spawn = require('child_process').spawn;
module.exports = function(grunt) {
grunt.initConfig({
cake: {
test: {}
},
watch: {
files: '**/*.coffee',
tasks: ['cake:test:all']
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerMultiTask('cake', 'Test with Cakefile.', function(){
var args = this.nameArgs.split(':');
var testArg = args.slice(1, args.length).join(':');
var done = this.async();
var cakeTest = spawn('cake', [testArg]);
cakeTest.stdout.on('data', function(data){ grunt.log.write(data.toString()); })
cakeTest.on('exit', function(code){ done(code); })
});
grunt.registerTask('default', 'watch');
};
@metaskills
Copy link
Author

My package.json has the following dev dependencies.

{ 
  // ...
  "devDependencies": {
    "grunt": "*",
    "grunt-contrib-watch": "*"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment