From 96380698c8e0e8ada3959dde5d692c94d82d2e41 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Fri, 6 Nov 2015 15:57:20 +0100 Subject: [PATCH 1/2] 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() { From 7cc31b107ff65d7213a049ad0966673a73c5afce Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Fri, 6 Nov 2015 16:31:05 +0100 Subject: [PATCH 2/2] Fix tests --- test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test.js b/test.js index ba79eadc..6d1339fb 100644 --- a/test.js +++ b/test.js @@ -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() {