4624b2a0d972ae732eea3ee7a6b4a2ce3a64d19b.svn-base
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var find = require('../');
var test = require('tap').test;
test('foo', function (t) {
var finder = find(__dirname + '/foo');
var ps = {};
var paths = []
finder.on('path', function (p, stat) {
paths.push(p);
ps[p] = stat.isDirectory();
});
var dirs = []
finder.on('directory', function (dir) {
dirs.push(dir);
});
var files = []
finder.on('file', function (file) {
files.push(file);
});
finder.on('end', function () {
var ref = {
'' : true,
'a' : true,
'a/b' : true,
'a/b/c' : true,
'x' : false,
'a/y' : false,
'a/b/z' : false,
'a/b/c/w' : false,
};
t.equal(Object.keys(ref).length, Object.keys(ps).length);
var count = { dirs : 0, files : 0, paths : 0 };
Object.keys(ref).forEach(function (key) {
var file = (__dirname + '/foo/' + key).replace(/\/$/, '');
t.equal(ref[key], ps[file]);
if (ref[key]) {
t.ok(dirs.indexOf(file) >= 0);
count.dirs ++;
}
else {
t.ok(files.indexOf(file) >= 0);
count.files ++;
}
});
t.deepEqual(count.dirs, dirs.length);
t.deepEqual(count.files, files.length);
t.deepEqual(paths.sort(), Object.keys(ps).sort());
t.end();
});
});