Skip to content

Commit

Permalink
fix: update old tests to use mocha instead
Browse files Browse the repository at this point in the history
  • Loading branch information
mklabs committed Jun 1, 2016
1 parent 954bab5 commit f4e0d8e
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/fileset.js
Expand Up @@ -94,6 +94,9 @@ fileset.Fileset = function Fileset(pattern, options, cb) {
if (typeof options === 'function') cb = options, options = {};
if (!options) options = {};

// ignore node_modules by default, unless specified
options.ignore = options.ignore || ['node_modules/**/*'];

Glob.call(this, pattern, options);

if (typeof cb === 'function') {
Expand Down
137 changes: 137 additions & 0 deletions test/mocha.js
Expand Up @@ -21,3 +21,140 @@ describe('Sync API - Given a *.md and **.js pattern, and two exclude', function(
assert.equal(results.length, 7, 'actually, should return only 7');
});
});

// Given a **.md pattern
describe('Given a **.md pattern', function() {
it('returns the list of matching file in this repo', function(done) {
fileset('*.md', function(err, results) {
if(err) return done(err);
assert.ok(Array.isArray(results), 'should be an array');
assert.ok(results.length, 'should return at least one element');
assert.equal(results.length, 2, 'actually, should return only two');
done();
});
});
});

describe('Say we want the **.js files, but not those in node_modules', function() {
it('recursively walks the dir and returns the matching list', function(done) {
fileset('**/*.js', '', function(err, results) {
if(err) return done(err);
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 11);
done();
});
});

it('recursively walks the dir and returns the matching list', function(done) {
fileset('**/*.js', function(err, results) {
if(err) return done(err);
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 11);
done();
});
});

it('supports multiple paths at once', function(done) {
fileset('**/*.js *.md', 'node_modules/**', function(err, results) {
if(err) return done(err);

assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 13);

assert.deepEqual(results, [
'CHANGELOG.md',
'README.md',
'lib/fileset.js',
'test/fixtures/an (odd) filename.js',
'test/fixtures/glob/common.js',
'test/fixtures/glob/glob.js',
'test/fixtures/glob/sync.js',
'test/fixtures/minimatch/minimatch.js',
'test/mocha.js',
'tests/fixtures/an (odd) filename.js',
'tests/helper.js',
'tests/test-sync.js',
'tests/test.js'
]);

done();
});
});

it('Should support multiple paths for excludes as well', function(done) {
fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) {
if(err) return done(err);
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 8);

assert.deepEqual(results, [
'lib/fileset.js',
'test/fixtures/an (odd) filename.js',
'test/fixtures/glob/common.js',
'test/fixtures/glob/glob.js',
'test/fixtures/glob/sync.js',
'test/fixtures/minimatch/minimatch.js',
'test/mocha.js',
'tests/fixtures/an (odd) filename.js',
]);

done();
});
});
});

describe('Testing out emmited events', function() {
it('recursively walk the dir and return the matching list', function(done) {
fileset('**/*.js', 'node_modules/**')
.on('error', done)
.on('end', function(results) {
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 11);
done();
});
});

it('support multiple paths at once', function(done) {
fileset('**/*.js *.md', 'node_modules/**')
.on('error', done)
.on('end', function(results) {
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 13);

assert.deepEqual(results, [
'CHANGELOG.md',
'README.md',
'lib/fileset.js',
'test/fixtures/an (odd) filename.js',
'test/fixtures/glob/common.js',
'test/fixtures/glob/glob.js',
'test/fixtures/glob/sync.js',
'test/fixtures/minimatch/minimatch.js',
'test/mocha.js',
'tests/fixtures/an (odd) filename.js',
'tests/helper.js',
'tests/test-sync.js',
'tests/test.js'
]);

done();
});
});
});

describe('Testing patterns passed as arrays', function() {
it('match files passed as an array with odd filenames', function(done) {
fileset(['lib/*.js', 'test/fixtures/an (odd) filename.js'], ['node_modules/**'])
.on('error', done)
.on('end', function(results) {
assert.ok(Array.isArray(results), 'should be an array');
assert.equal(results.length, 2);
assert.deepEqual(results, [
'lib/fileset.js',
'test/fixtures/an (odd) filename.js',
]);

done();
});
});
});

0 comments on commit f4e0d8e

Please sign in to comment.