5069f6ce0ba95d4f5fcc1a71d235fe556e517908.svn-base
2.4 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var test = require('tap').test;
var path = require('path');
var findit = require('../');
function helper(t, dir, options, callback) {
var symlinks = [];
var files = [];
var dirs = [];
var errors = [];
var finder = findit(dir, options);
finder.on('link', function (link, stat) {
t.ok(stat.isSymbolicLink());
symlinks.push(path.basename(link));
});
finder.on('file', function (file, stat) {
t.ok(stat.isFile());
files.push(path.basename(file));
});
finder.on('directory', function (dir, stat) {
t.ok(stat.isDirectory());
dirs.push(path.basename(dir));
});
finder.on('error', function (err) {
errors.push(err);
});
finder.on('end', function () {
symlinks.sort();
files.sort();
dirs.sort();
callback({
errors: errors,
symlinks: symlinks,
files: files,
dirs: dirs
});
});
}
test('links', function (t) {
helper(t, __dirname + '/symlinks/dir1', { followSymlinks: false }, done);
function done (data) {
t.deepEqual(data.errors, []);
t.deepEqual(data.symlinks, [
'dangling-symlink', 'link-to-dir2', 'link-to-file'
]);
t.deepEqual(data.files, [ 'file1' ]);
t.deepEqual(data.dirs, [ 'dir1' ]);
t.end();
}
});
test('follow links', function (t) {
helper(t, __dirname + '/symlinks/dir1', { followSymlinks: true }, done);
function done (data) {
t.equal(data.errors.length, 1);
t.equal(
data.errors[0].path, __dirname
+ '/symlinks/dir1/does-not-exist'
);
t.deepEqual(data.symlinks, [
'cyclic-link-to-dir1', 'dangling-symlink', 'link-to-dir2',
'link-to-file'
]);
t.deepEqual(data.files, ['file', 'file1', 'file2']);
t.deepEqual(data.dirs, [ 'dir1', 'link-to-dir2' ]);
t.end();
}
});
test('parent links', function (t) {
helper(t, __dirname + '/symlinks', { followSymlinks: true }, done);
function done (data) {
t.deepEqual(data.symlinks, [
'cyclic-link-to-dir1', 'dangling-symlink', 'link-to-dir2',
'link-to-file'
]);
t.deepEqual(data.files, ['file', 'file1', 'file2']);
t.deepEqual(data.dirs, [ 'dir1', 'dir2', 'symlinks' ]);
t.end();
}
});