2 var EventEmitter = require('events').EventEmitter;
\r
3 var fileset = require('../');
\r
4 var assert = require('assert');
\r
5 var test = require('./helper');
\r
7 // Given a **.md pattern
\r
8 test('Given a **.md pattern', function() {
\r
11 'should return the list of matching file in this repo': function(em) {
\r
12 fileset('*.md', function(err, results) {
\r
13 if(err) return em.emit('error', err);
\r
14 assert.ok(Array.isArray(results), 'should be an array');
\r
15 assert.ok(results.length, 'should return at least one element');
\r
16 assert.equal(results.length, 2, 'actually, should return only two');
\r
23 test('Say we want the **.js files, but not those in node_modules', function() {
\r
26 'Should recursively walk the dir and return the matching list': function(em) {
\r
27 fileset('**/*.js', 'node_modules/**', function(err, results) {
\r
28 if(err) return em.emit('error', err);
\r
29 assert.ok(Array.isArray(results), 'should be an array');
\r
30 assert.equal(results.length, 5);
\r
35 'Should support multiple paths at once': function(em) {
\r
36 fileset('**/*.js *.md', 'node_modules/**', function(err, results) {
\r
37 if(err) return em.emit('error', err);
\r
38 assert.ok(Array.isArray(results), 'should be an array');
\r
39 assert.equal(results.length, 7);
\r
41 assert.deepEqual(results, [
\r
45 'tests/fixtures/an (odd) filename.js',
\r
47 'tests/test-sync.js',
\r
55 'Should support multiple paths for excludes as well': function(em) {
\r
56 fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) {
\r
57 if(err) return em.emit('error', err);
\r
58 assert.ok(Array.isArray(results), 'should be an array');
\r
59 assert.equal(results.length, 2);
\r
61 assert.deepEqual(results, [
\r
63 'tests/fixtures/an (odd) filename.js',
\r
73 test('Testing out emmited events', function() {
\r
75 // todos: the tests for match, include, exclude events, but seems like it's ok
\r
77 'Should recursively walk the dir and return the matching list': function(em) {
\r
78 fileset('**/*.js', 'node_modules/**')
\r
79 .on('error', em.emit.bind(em, 'error'))
\r
80 .on('end', function(results) {
\r
81 assert.ok(Array.isArray(results), 'should be an array');
\r
82 assert.equal(results.length, 5);
\r
87 'Should support multiple paths at once': function(em) {
\r
88 fileset('**/*.js *.md', 'node_modules/**')
\r
89 .on('error', em.emit.bind(em, 'error'))
\r
90 .on('end', function(results) {
\r
91 assert.ok(Array.isArray(results), 'should be an array');
\r
92 assert.equal(results.length, 7);
\r
94 assert.deepEqual(results, [
\r
98 'tests/fixtures/an (odd) filename.js',
\r
100 'tests/test-sync.js',
\r
111 test('Testing patterns passed as arrays', function() {
\r
114 'Should match files passed as an array with odd filenames': function(em) {
\r
115 fileset(['lib/*.js', 'tests/fixtures/an (odd) filename.js'], ['node_modules/**'])
\r
116 .on('error', em.emit.bind(em, 'error'))
\r
117 .on('end', function(results) {
\r
118 assert.ok(Array.isArray(results), 'should be an array');
\r
119 assert.equal(results.length, 2);
\r
121 assert.deepEqual(results, [
\r
123 'tests/fixtures/an (odd) filename.js',
\r