Skip to content

Commit

Permalink
Fix crash when editing file inside watched directory
Browse files Browse the repository at this point in the history
Also better align behavior with `gulp.watch`.

Reference: #206 (comment)
  • Loading branch information
UltCombo committed Nov 10, 2015
1 parent 5c44dfc commit 678a8f1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ module.exports = function (globs, opts, cb) {
function processEvent(event, filepath) {
var glob = globs[anymatch(globs, filepath, true)];

if (!glob) {
return;
}

if (!baseForced) {
opts.base = glob2base(new Glob(glob));
}
Expand Down
37 changes: 37 additions & 0 deletions test/test-dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* global describe, it, afterEach */

var watch = require('..');
var path = require('path');
var fs = require('fs');
var rimraf = require('rimraf');
var touch = require('./touch.js');
require('should');

function fixtures(glob) {
return path.join(__dirname, 'fixtures', glob);
}

describe('dir', function () {
var w;

afterEach(function (done) {
rimraf.sync(fixtures('newDir'));
w.on('end', done);
w.close();
});

it('should not watch files inside directory', function (done) {
fs.mkdirSync(fixtures('newDir'));
touch(fixtures('newDir/index.js'))();
w = watch(fixtures('newDir'), function () {
done('Watched unexpected file.');
}).on('ready', function () {
touch(fixtures('newDir/index.js'))('new content');
setTimeout(done, 200);
});
});

it('should watch directory creation');

it('should watch directory removal');
});

0 comments on commit 678a8f1

Please sign in to comment.