Skip to content

Commit

Permalink
Fix: listTree must return an empty array if the directory does not ex…
Browse files Browse the repository at this point in the history
…ists

... just like q-io/fs
  • Loading branch information
nknapp committed Dec 20, 2016
1 parent 64ce630 commit 71da3f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ function walk (directoryPath, filter, collector) {
var defer = Q.defer()
fs.stat(directoryPath, function (err, stat) {
if (err) {
if (err.code === 'ENOENT') {
// Like q-io/fs, return an empty array, if the directory does not exist
return defer.resolve([])
}
return defer.reject(err)
}
// Call filter to get result, "true" if no filter is set
Expand Down
4 changes: 4 additions & 0 deletions test/fs-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ describe('m-io/fs', function () {
})

describe('the list-tree function', function () {
it('should return an empty array if the directory does not exist', function () {
return mfs.listTree('test/fixtures/no-directory').should.eventually.deep.equal([])
})

it('should return a file listing as array', function () {
return mfs.listTree('test/fixtures/tree').then(sort).should.eventually.deep.equal([
'test/fixtures/tree',
Expand Down

0 comments on commit 71da3f0

Please sign in to comment.