Skip to content

Commit

Permalink
Merge pull request #392 from nono/fix_awf_cwd
Browse files Browse the repository at this point in the history
Make awf and cwd options compatibles
  • Loading branch information
es128 committed Nov 6, 2015
2 parents 88a1da0 + 7cc31b1 commit f09d413
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@ FSWatcher.prototype._throttle = function(action, path, timeout) {
FSWatcher.prototype._awaitWriteFinish = function(path, threshold, callback) {
var timeoutHandler;

var fullPath = path;
if (this.options.cwd && !isAbsolute(path)) {
fullPath = sysPath.join(this.options.cwd, path);
}

(function awaitWriteFinish (prevStat) {
fs.stat(path, function(err, curStat) {
fs.stat(fullPath, function(err, curStat) {
if (err) {
delete this._pendingWrites[path];
if (err.code == 'ENOENT') return;
Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function rmFixtures() {
try { fs.rmdirSync(getFixturePath('subdir2/dir')); } catch(err) {}
try { fs.rmdirSync(getFixturePath('subdir2')); } catch(err) {}
try { fs.rmdirSync(getFixturePath('subdir')); } catch(err) {}
try { fs.unlinkSync(getFixturePath('awf_cwd/awf_cwd.txt')); } catch(err) {}
try { fs.rmdirSync(getFixturePath('awf_cwd')); } catch(err) {}
}

after(function() {
Expand Down Expand Up @@ -1392,6 +1394,21 @@ function runTests(options) {
})();
});
});
it('should be compatible with the cwd option', function(done) {
var spy = sinon.spy();
var testPath = getFixturePath('awf_cwd/awf_cwd.txt');
options.cwd = sysPath.dirname(testPath);
fs.mkdirSync(options.cwd);
stdWatcher()
.on('all', spy)
.on('ready', function() {
fs.writeFileSync(testPath, 'hello');
setTimeout(function() {
spy.should.have.been.calledWith('add');
done();
}, 1100);
});
});
});
});
describe('unwatch', function() {
Expand Down

0 comments on commit f09d413

Please sign in to comment.