Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80684 views
1
2
var EventEmitter = require('events').EventEmitter,
3
fileset = require('../'),
4
assert = require('assert'),
5
test = require('./helper');
6
7
// Given a **.coffee pattern
8
test('Given a **.md pattern', function() {
9
10
return {
11
'should return the list of matching file in this repo': function(em) {
12
fileset('*.md', function(err, results) {
13
if(err) return em.emit('error', err);
14
assert.ok(Array.isArray(results), 'should be an array');
15
assert.ok(results.length, 'should return at least one element');
16
assert.equal(results.length, 1, 'actually, should return only one');
17
em.emit('end');
18
});
19
}
20
}
21
});
22
23
test('Say we want the **.js files, but not those in node_modules', function() {
24
25
return {
26
'Should recursively walk the dir and return the matching list': function(em) {
27
fileset('**/*.js', 'node_modules/**', function(err, results) {
28
if(err) return em.emit('error', err);
29
assert.ok(Array.isArray(results), 'should be an array');
30
assert.equal(results.length, 4);
31
em.emit('end');
32
});
33
},
34
35
'Should support multiple paths at once': function(em) {
36
fileset('**/*.js *.md', 'node_modules/**', function(err, results) {
37
if(err) return em.emit('error', err);
38
assert.ok(Array.isArray(results), 'should be an array');
39
assert.equal(results.length, 5);
40
41
assert.deepEqual(results, [
42
'README.md',
43
'lib/fileset.js',
44
'tests/fixtures/an (odd) filename.js',
45
'tests/helper.js',
46
'tests/test.js'
47
]);
48
49
em.emit('end');
50
});
51
},
52
53
'Should support multiple paths for excludes as well': function(em) {
54
fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) {
55
if(err) return em.emit('error', err);
56
assert.ok(Array.isArray(results), 'should be an array');
57
assert.equal(results.length, 2);
58
59
assert.deepEqual(results, [
60
'lib/fileset.js',
61
'tests/fixtures/an (odd) filename.js',
62
]);
63
64
em.emit('end');
65
});
66
}
67
}
68
});
69
70
71
test('Testing out emmited events', function() {
72
73
// todos: the tests for match, include, exclude events, but seems like it's ok
74
return {
75
'Should recursively walk the dir and return the matching list': function(em) {
76
fileset('**/*.js', 'node_modules/**')
77
.on('error', em.emit.bind(em, 'error'))
78
.on('end', function(results) {
79
assert.ok(Array.isArray(results), 'should be an array');
80
assert.equal(results.length, 4);
81
em.emit('end');
82
});
83
},
84
85
'Should support multiple paths at once': function(em) {
86
fileset('**/*.js *.md', 'node_modules/**')
87
.on('error', em.emit.bind(em, 'error'))
88
.on('end', function(results) {
89
assert.ok(Array.isArray(results), 'should be an array');
90
assert.equal(results.length, 5);
91
92
assert.deepEqual(results, [
93
'README.md',
94
'lib/fileset.js',
95
'tests/fixtures/an (odd) filename.js',
96
'tests/helper.js',
97
'tests/test.js'
98
]);
99
100
em.emit('end');
101
});
102
}
103
}
104
});
105
106
107
test('Testing patterns passed as arrays', function() {
108
109
return {
110
'Should match files passed as an array with odd filenames': function(em) {
111
fileset(['lib/*.js', 'tests/fixtures/an (odd) filename.js'], ['node_modules/**'])
112
.on('error', em.emit.bind(em, 'error'))
113
.on('end', function(results) {
114
assert.ok(Array.isArray(results), 'should be an array');
115
assert.equal(results.length, 2);
116
117
assert.deepEqual(results, [
118
'lib/fileset.js',
119
'tests/fixtures/an (odd) filename.js',
120
]);
121
122
em.emit('end');
123
});
124
}
125
}
126
127
});
128
129
130
131
test.run();
132
133
134
135