Skip to content

Commit

Permalink
Update: Support ignore option in combination with negative globs
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Feb 21, 2017
1 parent 63dcc39 commit d617960
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var gs = {
var ourOpt = extend({}, opt);
delete ourOpt.root;

if (Array.isArray(opt.ignore)) {
negatives = opt.ignore.concat(negatives);
}
var ourNegatives = negatives.map(resolveNegatives);
ourOpt.ignore = ourNegatives;

Expand Down
50 changes: 50 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,54 @@ describe('glob-stream', function() {
});

});

describe('create() ignore option', function() {

it('should support the ignore option instead of negation', function(done) {
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc');
var glob = join(__dirname, './fixtures/stuff/*.dmc');
var stream = gs.create(glob, { cwd: __dirname, ignore: ['./fixtures/stuff/test.dmc'] });

var files = [];
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
files.push(file);
});
stream.on('end', function() {
files.length.should.equal(1);
files[0].path.should.equal(expectedPath);
done();
});
});

it('should support the ignore option with dot option', function(done) {
var stream = gs.create('./fixtures/*swag', { cwd: __dirname, dot: true, ignore: ['./fixtures/**'] });
should.exist(stream);
stream.on('error', function(err) {
throw err;
});
stream.once('data', function(file) {
throw new Error('file ' + file.path + ' should have been negated');
});
stream.once('end', done);
});

it('should merge ignore option and negative globs', function(done) {
var globArray = [
'./fixtures/stuff/*.dmc',
'!./fixtures/stuff/test.dmc',
];
var stream = gs.create(globArray, { cwd: __dirname, ignore: ['./fixtures/stuff/run.dmc'] });
should.exist(stream);
stream.on('error', function(err) {
throw err;
});
stream.once('data', function(file) {
throw new Error('file ' + file.path + ' should have been negated');
});
stream.once('end', done);
});
});
});

0 comments on commit d617960

Please sign in to comment.