diff --git a/index.js b/index.js index e71ac00..7cbdb71 100644 --- a/index.js +++ b/index.js @@ -14,5 +14,9 @@ module.exports = function isFile(path, cb){ module.exports.sync = isFileSync; function isFileSync(path){ - return fs.existsSync(path) && fs.statSync(path).isFile(); + try { + return fs.statSync(path).isFile(); + } catch (e) { + return false; + } } diff --git a/test/is-file.js b/test/is-file.js index d22fd1a..20bc2b8 100644 --- a/test/is-file.js +++ b/test/is-file.js @@ -38,5 +38,9 @@ describe('is-file', function(){ it('should return true for files', function(){ sut(__filename).should.be.true; }); + + it('should send back false when the path does not exist', function(){ + sut('asdasdf').should.be.false; + }); }); });