Skip to content

Commit

Permalink
Now errors if any singular blog isn't found
Browse files Browse the repository at this point in the history
  • Loading branch information
callumacrae committed Mar 15, 2015
1 parent f9e7bd8 commit 006467f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,21 @@ var gs = {
if (positives.length === 0) throw new Error('Missing positive glob');

// only one positive glob no need to aggregate
if (positives.length === 1) {
return streamFromPositive(positives[0]);
} else {
opt.allowEmpty = true;
}
if (positives.length === 1) return streamFromPositive(positives[0]);

// create all individual streams
var streams = positives.map(streamFromPositive);

// then just pipe them to a single unique stream and return it
var aggregate = new Combine(streams);
var uniqueStream = unique('path');
var returnStream = aggregate.pipe(uniqueStream);

aggregate.on('error', function (err) {
returnStream.emit('error', err);
});

return aggregate.pipe(uniqueStream);
return returnStream;

function streamFromPositive(positive) {
var negativeGlobs = negatives.filter(indexGreaterThan(positive.index)).map(toGlob);
Expand Down
18 changes: 8 additions & 10 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('glob-stream', function() {
var baseDir = join(__dirname, './fixtures');

var globArray = [
'./whatsgoingon/key/isaidhey/whatsgoingon/test.txt',
'./whatsgoingon/hey/isaidhey/whatsgoingon/test.txt',
'./test.coffee',
'./whatsgoingon/test.js'
];
Expand All @@ -97,7 +97,7 @@ describe('glob-stream', function() {
var baseDir = join(__dirname, './fixtures');

var globArray = [
'./whatsgoingon/key/isaidhey/whatsgoingon/test.txt',
'./whatsgoingon/hey/isaidhey/whatsgoingon/test.txt',
'./test.coffee',
'./whatsgoingon/test.js'
];
Expand Down Expand Up @@ -307,7 +307,7 @@ describe('glob-stream', function() {
var baseDir = join(__dirname, './fixtures');

var globArray = [
'./whatsgoingon/key/isaidhey/whatsgoingon/test.txt',
'./whatsgoingon/hey/isaidhey/whatsgoingon/test.txt',
'./test.coffee',
'./whatsgoingon/test.js'
];
Expand Down Expand Up @@ -493,15 +493,13 @@ describe('glob-stream', function() {
});
});

it('should not emit error when multiple globs not found', function(done) {
var stream = gs.create(['notfound', 'alsonotfound']);
it('should emit error when a glob in multiple globs not found', function(done) {
var stream = gs.create(['notfound', './fixtures/whatsgoingon'], {cwd: __dirname});
should.exist(stream);
stream.on('error', function() {
should.fail();
stream.on('error', function(err) {
err.should.match(/File not found with singular glob/);
done();
});

stream.resume();
stream.once('end', done);
});

it('should not emit error on glob containing {} when not found', function(done) {
Expand Down

0 comments on commit 006467f

Please sign in to comment.