Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt config watch and karma:unit in single task

Currently I have following Gruntfile configuration with two separate tasks and it works perfect:

grunt.registerTask('server', [
    'connect',
    'jshint',
    'less:dev',
    'watch'
]);

grunt.registerTask('test', [
    'karma:unit'
]);

I'd like to make one task that cover both things and log into one terminal window. Something like:

grunt.registerTask('dev', [
    'connect',
    'jshint',
    'less:dev',
    'karma:unit',
    'watch'
]);

The problem is that karma and watch can't work together. I've tried to put karma:unit:run to watch config and it works, but loads karma config on every file change. And this thing I don't like:

Running "karma:unit:run" (karma) task
[2014-05-25 01:40:24.466] [DEBUG] config - Loading config /Users/.../test/karma.config.js
PhantomJS 1.9.7 (Mac OS X): Executed 4 of 4 SUCCESS (0.011 secs / 0.012 secs)

Is there any possibility to resolve this issue or better to run those tasks separately?

like image 698
Artem Petrosian Avatar asked May 24 '14 22:05

Artem Petrosian


Video Answer


1 Answers

Use grunt-concurrent to run both the watch and karma tasks:

concurrent: {
  target: {
    tasks: ['karma:unit', 'watch']
  }
}

Then run the concurrent task from your dev task:

grunt.registerTask('dev', [
  'connect',
  'jshint',
  'less:dev',
  'concurrent:target'
]);
like image 80
steveax Avatar answered Oct 06 '22 00:10

steveax