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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
var test = require('tap').test
var rpt = require('../rpt.js')
var path = require('path')
var fs = require('fs')
var archy = require('archy')
var fixtures = path.resolve(__dirname, 'fixtures')
var roots = [ 'root', 'other', 'selflink' ]
var cwd = path.resolve(__dirname, '..')
var symlinks = {
'selflink/node_modules/@scope/z/node_modules/glob':
'../../../foo/node_modules/glob',
'other/node_modules/glob':
'../../root/node_modules/@scope/x/node_modules/glob',
'linkedroot':
'root',
'deep/root':
'../root',
'deeproot':
'deep'
}
function cleanup () {
Object.keys(symlinks).forEach(function (s) {
var p = path.resolve(cwd, 'test/fixtures', s)
try {
fs.unlinkSync(p)
} catch (er) {}
})
}
test('setup symlinks', function (t) {
cleanup()
Object.keys(symlinks).forEach(function (s) {
var p = path.resolve(cwd, 'test/fixtures', s)
fs.symlinkSync(symlinks [ s ], p, 'dir')
})
t.end()
})
roots.forEach(function (root) {
var dir = path.resolve(fixtures, root)
var out = path.resolve(dir, 'archy.txt')
test(root, function (t) {
rpt(dir, function (er, d) {
if (er && er.code !== 'ENOENT') throw er
var actual = archy(archyize(d)).trim()
// console . log ('----', dir)
console.log(actual)
// console . log (require ('util') . inspect (d, {
// depth: Infinity
// }))
var expect = fs.readFileSync(out, 'utf8').trim()
t.equal(actual, expect, root + ' tree')
t.end()
})
})
})
test('linkedroot', function (t) {
var dir = path.resolve(fixtures, 'linkedroot')
var out = dir + '-archy.txt'
rpt(dir, function (er, d) {
if (er && er.code !== 'ENOENT') throw er
var actual = archy(archyize(d)).trim()
console.log(actual)
var expect = fs.readFileSync(out, 'utf8').trim()
t.equal(actual, expect, 'linkedroot tree')
t.end()
})
})
test('deeproot', function (t) {
var dir = path.resolve(fixtures, 'deeproot/root')
var out = path.resolve(fixtures, 'deep') + '-archy.txt'
rpt(dir, function (er, d) {
if (er && er.code !== 'ENOENT') throw er
var actual = archy(archyize(d)).trim()
console.log(actual)
var expect = fs.readFileSync(out, 'utf8').trim()
t.equal(actual, expect, 'deeproot tree')
t.end()
})
})
test('broken json', function (t) {
rpt(path.resolve(fixtures, 'bad'), function (er, d) {
t.ok(er, 'Got an error object')
t.equal(er && er.code, 'EJSONPARSE')
t.ok(d, 'Got a tree')
t.end()
})
})
test('missing json does not obscure deeper errors', function (t) {
rpt(path.resolve(fixtures, 'empty'), function (er, d) {
t.ok(er, 'Got an error object')
t.equal(er && er.code, 'EJSONPARSE')
t.ok(!d, 'No tree on internal error')
t.end()
})
})
function archyize (d, seen) {
seen = seen || {}
var path = d.path
if (d.target) {
path = d.target.path
}
var label = d.package ? d.package._id + ' ' : ''
label += path.substr(cwd.length + 1)
if (d . target) {
return { label: label + ' (symlink)', nodes: [] }
}
return {
label: label,
nodes: d.children.map(function (kid) {
return archyize(kid, seen)
})
}
}
test('cleanup', function (t) {
cleanup()
t.end()
})
|