Skip to content

Fix readdirpromise #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/iterators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -239,9 +239,13 @@ module.exports = function (app) {
});
})


.reduce(function (acc, files) {
return acc.concat(files);
}, []);
}, [])
.filter(function(file) {
return file !== null;
});
},

});
Expand Down
6 changes: 4 additions & 2 deletions lib/readers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
});
};
Empty file.
Empty file added test/fixtures/a/c/d/e/f/i/i.js
Empty file.
1 change: 1 addition & 0 deletions test/gitignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});

Expand Down
70 changes: 70 additions & 0 deletions test/promise.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
2 changes: 1 addition & 1 deletion test/slashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down