简体   繁体   中英

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?

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'
]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM