Skip to content

Commit

Permalink
feat(watcher): Allow using braces in watcher
Browse files Browse the repository at this point in the history
Expands braces in watcher, so you can watch: ['a/{b,c}'] which would
expand to ['a/b', 'a/c']

Closes karma-runner#1249
  • Loading branch information
JetFault committed Nov 24, 2014
1 parent 85328f3 commit 5affa28
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lib/watcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var chokidar = require('chokidar');
var mm = require('minimatch');
var expandBraces = require('expand-braces');

var helper = require('./helper');
var log = require('./logger').create('watcher');
Expand All @@ -19,6 +20,9 @@ var watchPatterns = function(patterns, watcher) {
var uniqueMap = {};
var path;

// expand ['a/{b,c}'] to ['a/b', 'a/c']
patterns = expandBraces(patterns);

patterns.forEach(function(pattern) {
path = baseDirFromPattern(pattern);
if (!uniqueMap[path]) {
Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,24 @@
"Jeff Froom <jeff@jfroom.com>"
],
"dependencies": {
"di": "~0.0.1",
"socket.io": "~0.9.13",
"chokidar": ">=0.8.2",
"colors": "~0.6.2",
"connect": "~2.26.0",
"di": "~0.0.1",
"expand-braces": "^0.1.1",
"glob": "~3.2.7",
"minimatch": "~0.2",
"graceful-fs": "~2.0.1",
"http-proxy": "~0.10",
"optimist": "~0.6.0",
"rimraf": "~2.2.5",
"q": "~0.9.7",
"colors": "~0.6.2",
"lodash": "~2.4.1",
"mime": "~1.2.11",
"log4js": "~0.6.3",
"useragent": "~2.0.4",
"graceful-fs": "~2.0.1",
"connect": "~2.26.0",
"source-map": "~0.1.31"
"mime": "~1.2.11",
"minimatch": "~0.2",
"optimist": "~0.6.0",
"q": "~0.9.7",
"rimraf": "~2.2.5",
"socket.io": "~0.9.13",
"source-map": "~0.1.31",
"useragent": "~2.0.4"
},
"devDependencies": {
"grunt": "~0.4",
Expand Down
15 changes: 15 additions & 0 deletions test/unit/watcher.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ describe 'watcher', ->
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some', '/a']


it 'should expand braces and watch all the patterns', ->
m.watchPatterns ['/some/{a,b}/*.js', '/a/*'], chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some/a', '/some/b', '/a']


it 'should not watch the same path twice', ->
m.watchPatterns ['/some/a*.js', '/some/*.txt'], chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some']


it 'should not watch the same path twice when using braces', ->
m.watchPatterns ['/some/*.{js,txt}'], chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some']


it 'should not watch subpaths that are already watched', ->
m.watchPatterns ['/some/sub/*.js', '/some/a*.*'].map(path.normalize), chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal [path.normalize('/some')]
Expand All @@ -75,6 +85,11 @@ describe 'watcher', ->
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some/test-file.js', '/some/test']


it 'should watch files matching a subpath directory with braces', ->
m.watchPatterns ['/some/{a,b}/test.js'], chokidarWatcher
expect(chokidarWatcher.watchedPaths_).to.deep.equal ['/some/a/test.js', '/some/b/test.js']


describe 'getWatchedPatterns', ->

it 'should return list of watched patterns (strings)', ->
Expand Down

0 comments on commit 5affa28

Please sign in to comment.