diff --git a/lib/watcher.js b/lib/watcher.js index 9c55f6782..b58b840c0 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -73,7 +73,7 @@ var getWatchedPatterns = function(patternObjects) { }); }; -exports.watch = function(patterns, excludes, fileList, usePolling) { +exports.watch = function(patterns, excludes, fileList, usePolling, emitter) { var watchedPatterns = getWatchedPatterns(patterns); var options = { usePolling: usePolling, @@ -101,7 +101,13 @@ exports.watch = function(patterns, excludes, fileList, usePolling) { log.debug(e); }); + emitter.on('exit', function(done) { + chokidarWatcher.close(); + done(); + }); + return chokidarWatcher; }; -exports.watch.$inject = ['config.files', 'config.exclude', 'fileList', 'config.usePolling']; +exports.watch.$inject = ['config.files', 'config.exclude', 'fileList', 'config.usePolling', + 'emitter'];