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
|
const { test } = require('tap')
const requireInject = require('require-inject')
test('bin', (t) => {
t.plan(3)
const dir = '/bin/dir'
const Bin = require('../../lib/bin.js')
const npm = {
bin: dir,
flatOptions: { global: false },
output: (output) => {
t.equal(output, dir, 'prints the correct directory')
},
}
const bin = new Bin(npm)
bin.exec([], (err) => {
t.ifError(err, 'npm bin')
t.ok('should have printed directory')
})
})
test('bin -g', (t) => {
t.plan(3)
const consoleError = console.error
t.tearDown(() => {
console.error = consoleError
})
console.error = (output) => {
t.fail('should not have printed to console.error')
}
const dir = '/bin/dir'
const Bin = requireInject('../../lib/bin.js', {
'../../lib/utils/path.js': [dir],
})
const npm = {
bin: dir,
flatOptions: { global: true },
output: (output) => {
t.equal(output, dir, 'prints the correct directory')
},
}
const bin = new Bin(npm)
bin.exec([], (err) => {
t.ifError(err, 'npm bin')
t.ok('should have printed directory')
})
})
test('bin -g (not in path)', (t) => {
t.plan(4)
const consoleError = console.error
t.tearDown(() => {
console.error = consoleError
})
console.error = (output) => {
t.equal(output, '(not in PATH env variable)', 'prints env warning')
}
const dir = '/bin/dir'
const Bin = requireInject('../../lib/bin.js', {
'../../lib/utils/path.js': ['/not/my/dir'],
})
const npm = {
bin: dir,
flatOptions: { global: true },
output: (output) => {
t.equal(output, dir, 'prints the correct directory')
},
}
const bin = new Bin(npm)
bin.exec([], (err) => {
t.ifError(err, 'npm bin')
t.ok('should have printed directory')
})
})
|