diff --git a/lib/iterators.js b/lib/iterators.js index f287210..5e4b60f 100644 --- a/lib/iterators.js +++ b/lib/iterators.js @@ -223,7 +223,7 @@ module.exports = function (app) { // emit excluded file if (file.exclude === true) { self.emit('exclude', file); - return file.path; + return null; } // emit included file @@ -239,9 +239,13 @@ module.exports = function (app) { }); }) + .reduce(function (acc, files) { return acc.concat(files); - }, []); + }, []) + .filter(function(file) { + return file !== null; + }); }, }); diff --git a/lib/readers.js b/lib/readers.js index 919fe9f..896637e 100644 --- a/lib/readers.js +++ b/lib/readers.js @@ -99,8 +99,10 @@ module.exports = function (app) { this.emit('read'); this.setPattern(pattern, options); var res = this.iteratorPromise(this.pattern.base); - this.emit('end', this.files); - return res; + return res.then(() => { + this.emit('end', this.files); + return this.files; + }); } }); }; diff --git a/test/fixtures/a/c/d/e/f/g/h/h.js b/test/fixtures/a/c/d/e/f/g/h/h.js new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/a/c/d/e/f/i/i.js b/test/fixtures/a/c/d/e/f/i/i.js new file mode 100644 index 0000000..e69de29 diff --git a/test/gitignore.js b/test/gitignore.js index f5e1d1e..3aa92a8 100644 --- a/test/gitignore.js +++ b/test/gitignore.js @@ -27,6 +27,7 @@ describe('gitignore', function () { }); it('should recurse into node_modules when it\'s specified in the glob pattern:', function () { + glob = new Glob({ gitignore: false }) glob.readdirSync('./node_modules/micromatch/*.js').should.containDeep(['node_modules/micromatch/index.js']); }); diff --git a/test/promise.js b/test/promise.js new file mode 100644 index 0000000..185a339 --- /dev/null +++ b/test/promise.js @@ -0,0 +1,70 @@ +'use strict'; + +var should = require('should'); +var Glob = require('..'); +var path = require('path'); +var orig = process.cwd(); +var glob; + +describe("promise", function () { + before(function () { + process.chdir(__dirname + '/fixtures'); + }); + + after(function () { + process.chdir(orig); + }); + var mm = require('micromatch'); + + beforeEach(function () { + glob = new Glob(); + + glob.on('file', function (file) { + // console.log(mm.isMatch(file.relative, 'a/*/*/*/**/')) + }); + + glob.on('read', function () { + glob.files = []; + }); + }); + + it('should only return directories when the pattern ends in a slash:', function () { + return glob.readdirPromise('a/*/').then(function(files) { + (files.length).should.eql(3); + (files.includes('a/b/')).should.eql(true); + (files.includes('a/c/')).should.eql(true); + (files.includes('a/bc/')).should.eql(true); + }); + }); + + it('should not resolve with excluded matches:', function () { + function exclude(file) { + file.exclude = (file.path.indexOf('bc') === -1); + return file; + } + + return glob.use(exclude).readdirPromise('a/*/').then(function(files) { + (files.length).should.eql(1); + (files.includes('a/bc/')).should.eql(true); + }); + }); + + it('should only return files that match and not the directories containing them:', function () { + return glob.readdirPromise('a/bc/e/f/*').then(function(files) { + (files.length).should.eql(1); + (files.includes('a/bc/e/f/fff.js')).should.eql(true); + }); + }); + + it('should emit the correct values when completed:', function () { + var emittedFiles = []; + glob.on('end', function(files) { + emittedFiles = files; + }); + + return glob.readdirPromise('a/bc/e/f/*').then(function(files) { + (emittedFiles.length).should.eql(1); + (emittedFiles.includes('a/bc/e/f/fff.js')).should.eql(true); + }); + }); +}); diff --git a/test/slashes.js b/test/slashes.js index 599ff3b..97f49fc 100644 --- a/test/slashes.js +++ b/test/slashes.js @@ -6,7 +6,7 @@ var path = require('path'); var orig = process.cwd(); var glob; -describe("root", function () { +describe("slashes", function () { before(function () { process.chdir(__dirname + '/fixtures'); });