Skip to content

Commit

Permalink
fix: watch does not work for glob pattern '<dir>/**' if '<dir>' does …
Browse files Browse the repository at this point in the history
…not exist on fs
  • Loading branch information
eGavr committed Jul 16, 2018
1 parent 8cd5f7a commit af71c17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ FSWatcher.prototype._isIgnored = function(path, stats) {
var replacerRe = /^\.[\/\\]/;
FSWatcher.prototype._getWatchHelpers = function(path, depth) {
path = path.replace(replacerRe, '');
var watchPath = depth || this.options.disableGlobbing || !isGlob(path) ? path : globParent(path);
var getExistingPath = function(path) { return fs.existsSync(path) ? path : getExistingPath(sysPath.dirname(path)); };
var watchPath = depth || this.options.disableGlobbing || !isGlob(path) ? path : getExistingPath(globParent(path));
var fullWatchPath = sysPath.resolve(watchPath);
var hasGlob = watchPath !== path;
var globFilter = hasGlob ? anymatch(path) : false;
Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,23 @@ function runTests(baseopts) {
});
});
});
it('should correctly watch glob patterns which initially do not match any files on fs', (done) => {
var spy = sinon.spy();
var watchPath = upath.normalizeSafe(getGlobPath('subdir/**'));
var dir = getFixturePath('subdir');
var file = getFixturePath('subdir/a.txt');
watcher = chokidar.watch(watchPath, options)
.on('all', spy)
.on('ready', function() {
fs.mkdirSync(getFixturePath('subdir'), 0x1ed);
fs.writeFileSync(file, Date.now());
waitFor([spy.withArgs('add')], function() {
spy.should.have.been.calledWith('addDir', dir);
spy.should.have.been.calledWith('add', file);
});
done();
});
});
});
describe('watch symlinks', function() {
if (os === 'win32') return;
Expand Down

0 comments on commit af71c17

Please sign in to comment.