-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: consolidate path delimiter logic
- Loading branch information
1 parent
57d8f75
commit 0a957f5
Showing
5 changed files
with
26 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,32 @@ | ||
const t = require('tap') | ||
const { relative, join } = require('path') | ||
const { load: loadMockNpm } = require('../../fixtures/mock-npm') | ||
const mockGlobals = require('../../fixtures/mock-globals') | ||
|
||
const mockBin = async (t, { args = [], config = {} } = {}) => { | ||
const { npm, outputs, ...rest } = await loadMockNpm(t, { | ||
config, | ||
}) | ||
const cmd = await npm.cmd('bin') | ||
await npm.exec('bin', args) | ||
|
||
return { | ||
npm, | ||
cmd, | ||
bin: outputs[0][0], | ||
...rest, | ||
} | ||
} | ||
|
||
t.test('bin', async t => { | ||
const { cmd, bin, prefix, outputErrors } = await mockBin(t, { | ||
config: { global: false }, | ||
}) | ||
|
||
t.match(cmd.usage, 'bin', 'usage has command name in it') | ||
t.equal(relative(prefix, bin), join('node_modules/.bin'), 'prints the correct directory') | ||
t.strictSame(outputErrors, []) | ||
t.test('bin not global', async t => { | ||
const { npm, joinedOutput, logs } = await loadMockNpm(t) | ||
await npm.exec('bin', []) | ||
t.match(joinedOutput(), npm.localBin) | ||
t.match(logs.error, []) | ||
}) | ||
|
||
t.test('bin -g', async t => { | ||
mockGlobals(t, { 'process.platform': 'posix' }) | ||
const { globalPrefix, bin, outputErrors } = await mockBin(t, { | ||
t.test('bin global in env.path', async t => { | ||
const { npm, joinedOutput, logs } = await loadMockNpm(t, { | ||
config: { global: true }, | ||
}) | ||
|
||
t.equal(relative(globalPrefix, bin), 'bin', 'prints the correct directory') | ||
t.strictSame(outputErrors, []) | ||
}) | ||
|
||
t.test('bin -g win32', async t => { | ||
mockGlobals(t, { 'process.platform': 'win32' }) | ||
const { globalPrefix, bin, outputErrors } = await mockBin(t, { | ||
config: { global: true }, | ||
mockGlobals(t, { | ||
'process.env': { path: npm.globalBin }, | ||
}) | ||
|
||
t.equal(relative(globalPrefix, bin), '', 'prints the correct directory') | ||
t.strictSame(outputErrors, []) | ||
await npm.exec('bin', []) | ||
t.match(joinedOutput(), npm.globalBin) | ||
t.match(logs.error, []) | ||
}) | ||
|
||
t.test('bin -g (not in path)', async t => { | ||
const { logs } = await mockBin(t, { | ||
t.test('bin not in path', async t => { | ||
const { npm, joinedOutput, logs } = await loadMockNpm(t, { | ||
config: { global: true }, | ||
globals: { | ||
'process.env.PATH': 'emptypath', | ||
}, | ||
}) | ||
|
||
t.strictSame(logs.error[0], ['bin', '(not in PATH env variable)']) | ||
await npm.exec('bin', []) | ||
t.match(joinedOutput(), npm.globalBin) | ||
t.match(logs.error, [['bin', '(not in PATH env variable)']]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.