diff --git a/lib/watcher.js b/lib/watcher.js index ce76e3758..78ae30adc 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -8,7 +8,9 @@ var DIR_SEP = require('path').sep; // Get parent folder, that be watched (does not contain any special globbing character) var baseDirFromPattern = function(pattern) { - return pattern.replace(/\/[^\/]*[\*\(].*$/, '') || '/'; + return pattern.replace(/\/[^\/]*\*.*$/, '') // remove parts with * + .replace(/\/[^\/]*[\!\+]\(.*$/, '') // remove parts with !(...) and +(...) + .replace(/\/[^\/]*\)\?.*$/, '') || '/'; // remove parts with (...)? }; var watchPatterns = function(patterns, watcher) { diff --git a/test/unit/watcher.spec.coffee b/test/unit/watcher.spec.coffee index 7d4a72006..831bcec2f 100644 --- a/test/unit/watcher.spec.coffee +++ b/test/unit/watcher.spec.coffee @@ -20,9 +20,24 @@ describe 'watcher', -> expect(m.baseDirFromPattern '/some/p*/file.js').to.equal '/some' - it 'should remove part with parenthesis', -> - expect(m.baseDirFromPattern '/some/p/(a|b).js').to.equal '/some/p' - expect(m.baseDirFromPattern '/some/p(c|b)*.js').to.equal '/some' + it 'should remove part with !(x)', -> + expect(m.baseDirFromPattern '/some/p/!(a|b).js').to.equal '/some/p' + expect(m.baseDirFromPattern '/some/p!(c|b)*.js').to.equal '/some' + + + it 'should remove part with +(x)', -> + expect(m.baseDirFromPattern '/some/p/+(a|b).js').to.equal '/some/p' + expect(m.baseDirFromPattern '/some/p+(c|bb).js').to.equal '/some' + + + it 'should remove part with (x)?', -> + expect(m.baseDirFromPattern '/some/p/(a|b)?.js').to.equal '/some/p' + expect(m.baseDirFromPattern '/some/p(c|b)?.js').to.equal '/some' + + + it 'should allow paths with parentheses', -> + expect(m.baseDirFromPattern '/some/x (a|b)/a.js').to.equal '/some/x (a|b)/a.js' + expect(m.baseDirFromPattern '/some/p(c|b)/*.js').to.equal '/some/p(c|b)' it 'should ignore exact files', ->