Skip to content

Commit

Permalink
Support for include/excludes as arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Feb 6, 2013
1 parent 121e422 commit a7982b0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/fileset.js
Expand Up @@ -9,9 +9,10 @@ function fileset(include, exclude, options, cb) {
if (typeof exclude === 'function') cb = exclude, exclude = '';
else if (typeof options === 'function') cb = options, options = {};

var includes = (typeof include === 'string') ? include.split(' ') : include;
var excludes = (typeof exclude === 'string') ? exclude.split(' ') : exclude;

var em = new EventEmitter,
includes = include.split(' '),
excludes = exclude.split(' '),
remaining = includes.length,
results = [];

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/an (odd) filename.js
@@ -0,0 +1 @@
var odd = true;
38 changes: 32 additions & 6 deletions tests/test.js
Expand Up @@ -27,7 +27,7 @@ test('Say we want the **.js files, but not those in node_modules', function() {
fileset('**/*.js', 'node_modules/**', function(err, results) {
if(err) return em.emit('error', err);
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 3);
assert.equal(results.length, 4);
em.emit('end');
});
},
Expand All @@ -36,11 +36,12 @@ test('Say we want the **.js files, but not those in node_modules', function() {
fileset('**/*.js *.md', 'node_modules/**', function(err, results) {
if(err) return em.emit('error', err);
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 4);
assert.equal(results.length, 5);

assert.deepEqual(results, [
'README.md',
'lib/fileset.js',
'tests/fixtures/an (odd) filename.js',
'tests/helper.js',
'tests/test.js'
]);
Expand All @@ -53,10 +54,11 @@ test('Say we want the **.js files, but not those in node_modules', function() {
fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) {
if(err) return em.emit('error', err);
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 1);
assert.equal(results.length, 2);

assert.deepEqual(results, [
'lib/fileset.js'
'lib/fileset.js',
'tests/fixtures/an (odd) filename.js',
]);

em.emit('end');
Expand All @@ -75,7 +77,7 @@ test('Testing out emmited events', function() {
.on('error', em.emit.bind(em, 'error'))
.on('end', function(results) {
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 3);
assert.equal(results.length, 4);
em.emit('end');
});
},
Expand All @@ -85,11 +87,12 @@ test('Testing out emmited events', function() {
.on('error', em.emit.bind(em, 'error'))
.on('end', function(results) {
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 4);
assert.equal(results.length, 5);

assert.deepEqual(results, [
'README.md',
'lib/fileset.js',
'tests/fixtures/an (odd) filename.js',
'tests/helper.js',
'tests/test.js'
]);
Expand All @@ -101,6 +104,29 @@ test('Testing out emmited events', function() {
});


test('Testing patterns passed as arrays', function() {

return {
'Should match files passed as an array with odd filenames': function(em) {
fileset(['lib/*.js', 'tests/fixtures/an (odd) filename.js'], ['node_modules/**'])
.on('error', em.emit.bind(em, 'error'))
.on('end', function(results) {
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 2);

assert.deepEqual(results, [
'lib/fileset.js',
'tests/fixtures/an (odd) filename.js',
]);

em.emit('end');
});
}
}

});



test.run();

Expand Down

0 comments on commit a7982b0

Please sign in to comment.