From 96380698c8e0e8ada3959dde5d692c94d82d2e41 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Fri, 6 Nov 2015 15:57:20 +0100 Subject: [PATCH] Make awf and cwd options compatibles --- index.js | 7 ++++++- test.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1c3fe9f6..c07de0a0 100755 --- a/index.js +++ b/index.js @@ -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; diff --git a/test.js b/test.js index 77e0277c..ba79eadc 100644 --- a/test.js +++ b/test.js @@ -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() {