Skip to content

Commit

Permalink
Make awf and cwd options compatibles
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Nov 6, 2015
1 parent 88a1da0 commit 9638069
Show file tree
Hide file tree
Showing 2 changed files with 21 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
15 changes: 15 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,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 9638069

Please sign in to comment.