|
1 | 1 | const t = require('tap') |
2 | | -const { relative, join } = require('path') |
3 | 2 | const { load: loadMockNpm } = require('../../fixtures/mock-npm') |
4 | 3 | const mockGlobals = require('../../fixtures/mock-globals') |
5 | 4 |
|
6 | | -const mockBin = async (t, { args = [], config = {} } = {}) => { |
7 | | - const { npm, outputs, ...rest } = await loadMockNpm(t, { |
8 | | - config, |
9 | | - }) |
10 | | - const cmd = await npm.cmd('bin') |
11 | | - await npm.exec('bin', args) |
12 | | - |
13 | | - return { |
14 | | - npm, |
15 | | - cmd, |
16 | | - bin: outputs[0][0], |
17 | | - ...rest, |
18 | | - } |
19 | | -} |
20 | | - |
21 | | -t.test('bin', async t => { |
22 | | - const { cmd, bin, prefix, outputErrors } = await mockBin(t, { |
23 | | - config: { global: false }, |
24 | | - }) |
25 | | - |
26 | | - t.match(cmd.usage, 'bin', 'usage has command name in it') |
27 | | - t.equal(relative(prefix, bin), join('node_modules/.bin'), 'prints the correct directory') |
28 | | - t.strictSame(outputErrors, []) |
| 5 | +t.test('bin not global', async t => { |
| 6 | + const { npm, joinedOutput, logs } = await loadMockNpm(t) |
| 7 | + await npm.exec('bin', []) |
| 8 | + t.match(joinedOutput(), npm.localBin) |
| 9 | + t.match(logs.error, []) |
29 | 10 | }) |
30 | 11 |
|
31 | | -t.test('bin -g', async t => { |
32 | | - mockGlobals(t, { 'process.platform': 'posix' }) |
33 | | - const { globalPrefix, bin, outputErrors } = await mockBin(t, { |
| 12 | +t.test('bin global in env.path', async t => { |
| 13 | + const { npm, joinedOutput, logs } = await loadMockNpm(t, { |
34 | 14 | config: { global: true }, |
35 | 15 | }) |
36 | 16 |
|
37 | | - t.equal(relative(globalPrefix, bin), 'bin', 'prints the correct directory') |
38 | | - t.strictSame(outputErrors, []) |
39 | | -}) |
40 | | - |
41 | | -t.test('bin -g win32', async t => { |
42 | | - mockGlobals(t, { 'process.platform': 'win32' }) |
43 | | - const { globalPrefix, bin, outputErrors } = await mockBin(t, { |
44 | | - config: { global: true }, |
| 17 | + mockGlobals(t, { |
| 18 | + 'process.env': { path: npm.globalBin }, |
45 | 19 | }) |
46 | | - |
47 | | - t.equal(relative(globalPrefix, bin), '', 'prints the correct directory') |
48 | | - t.strictSame(outputErrors, []) |
| 20 | + await npm.exec('bin', []) |
| 21 | + t.match(joinedOutput(), npm.globalBin) |
| 22 | + t.match(logs.error, []) |
49 | 23 | }) |
50 | 24 |
|
51 | | -t.test('bin -g (not in path)', async t => { |
52 | | - const { logs } = await mockBin(t, { |
| 25 | +t.test('bin not in path', async t => { |
| 26 | + const { npm, joinedOutput, logs } = await loadMockNpm(t, { |
53 | 27 | config: { global: true }, |
54 | | - globals: { |
55 | | - 'process.env.PATH': 'emptypath', |
56 | | - }, |
57 | 28 | }) |
58 | | - |
59 | | - t.strictSame(logs.error[0], ['bin', '(not in PATH env variable)']) |
| 29 | + await npm.exec('bin', []) |
| 30 | + t.match(joinedOutput(), npm.globalBin) |
| 31 | + t.match(logs.error, [['bin', '(not in PATH env variable)']]) |
60 | 32 | }) |
0 commit comments