2 var EventEmitter = require('events').EventEmitter,
\r
3 fileset = require('../'),
\r
4 assert = require('assert'),
\r
5 test = require('./helper');
\r
7 // Given a **.coffee 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, 1, 'actually, should return only one');
\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, 4);
\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, 5);
\r
41 assert.deepEqual(results, [
\r
44 'tests/fixtures/an (odd) filename.js',
\r
53 'Should support multiple paths for excludes as well': function(em) {
\r
54 fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) {
\r
55 if(err) return em.emit('error', err);
\r
56 assert.ok(Array.isArray(results), 'should be an array');
\r
57 assert.equal(results.length, 2);
\r
59 assert.deepEqual(results, [
\r
61 'tests/fixtures/an (odd) filename.js',
\r
71 test('Testing out emmited events', function() {
\r
73 // todos: the tests for match, include, exclude events, but seems like it's ok
\r
75 'Should recursively walk the dir and return the matching list': function(em) {
\r
76 fileset('**/*.js', 'node_modules/**')
\r
77 .on('error', em.emit.bind(em, 'error'))
\r
78 .on('end', function(results) {
\r
79 assert.ok(Array.isArray(results), 'should be an array');
\r
80 assert.equal(results.length, 4);
\r
85 'Should support multiple paths at once': function(em) {
\r
86 fileset('**/*.js *.md', 'node_modules/**')
\r
87 .on('error', em.emit.bind(em, 'error'))
\r
88 .on('end', function(results) {
\r
89 assert.ok(Array.isArray(results), 'should be an array');
\r
90 assert.equal(results.length, 5);
\r
92 assert.deepEqual(results, [
\r
95 'tests/fixtures/an (odd) filename.js',
\r
107 test('Testing patterns passed as arrays', function() {
\r
110 'Should match files passed as an array with odd filenames': function(em) {
\r
111 fileset(['lib/*.js', 'tests/fixtures/an (odd) filename.js'], ['node_modules/**'])
\r
112 .on('error', em.emit.bind(em, 'error'))
\r
113 .on('end', function(results) {
\r
114 assert.ok(Array.isArray(results), 'should be an array');
\r
115 assert.equal(results.length, 2);
\r
117 assert.deepEqual(results, [
\r
119 'tests/fixtures/an (odd) filename.js',
\r