Skip to content

Commit

Permalink
fix(watcher): honor 'watched: false' in patterns.
Browse files Browse the repository at this point in the history
Includes the patterns for files to include, but not to watch, in
addition to the excludes list when creating a list of patterns
to ignore. This makes the watcher ignore patterns marked as
"watched: false" in karma's configuration file.

Closes: karma-runner#616
  • Loading branch information
Joakim Karlsson committed Jul 4, 2013
1 parent 42bf787 commit 3d46fd6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var mm = require('minimatch');

var helper = require('./helper');
var log = require('./logger').create('watcher');
var _ = require('lodash');

var DIR_SEP = require('path').sep;

Expand Down Expand Up @@ -45,20 +46,25 @@ var watchPatterns = function(patterns, watcher) {
// Function to test if an item is on the exclude list
// and therefore should not be watched by chokidar
// TODO(vojta): ignore non-matched files as well
var createIgnore = function(excludes) {
var createIgnore = function(excludes, patterns) {
var ex = _(patterns)
.filter(function(p) { return !(p.watched); })
.map('pattern')
.concat(excludes);

return function(item) {
var matchExclude = function(pattern) {
log.debug('Excluding %s', pattern);
return mm(item, pattern, {dot: true});
};
return excludes.some(matchExclude);
return ex.some(matchExclude);
};
};

exports.watch = function(patterns, excludes, fileList) {
var options = {
ignorePermissionErrors: true,
ignored: createIgnore(excludes)
ignored: createIgnore(excludes, patterns)
};
var chokidarWatcher = new chokidar.FSWatcher(options);

Expand Down
18 changes: 18 additions & 0 deletions test/unit/watcher.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,21 @@ describe 'watcher', ->
expect(ignore '/some/files/deep/.npm').to.equal false
expect(ignore '.#files.js').to.equal true
expect(ignore '/some/files/deeper/nested/.#files.js').to.equal true

it 'should ignore patterns with watched: false', ->
ignore = m.createIgnore [], [{pattern: 'app/*.html', watched: false}]
expect(ignore 'app/app.html').to.equal true

it 'should not ignore patterns with watched: true', ->
ignore = m.createIgnore [], [{pattern: 'app/*.html', watched: true}]
expect(ignore 'app/app.html').to.equal false

it 'should combine exclude and patterns', ->
ignore = m.createIgnore ['app/*.ignoreme'], [
{pattern: 'app/*.html', watched: false},
{pattern: 'app/*.js', watched: true}]

expect(ignore 'app/please.ignoreme').to.equal true
expect(ignore 'app/dontwatch.html').to.equal true
expect(ignore 'app/dowatch.js').to.equal false

0 comments on commit 3d46fd6

Please sign in to comment.