diff options
author | Gar <gar+gh@danger.computer> | 2022-03-24 19:09:26 +0300 |
---|---|---|
committer | Luke Karrys <luke@lukekarrys.com> | 2022-03-28 23:21:36 +0300 |
commit | 0a957f5e2fbcce51c407d22b19e38004d09c51af (patch) | |
tree | d69aad0531c04ecd010f3b245b102a0e5a288df2 /test | |
parent | 57d8f75eb864486f6aa17bb3dd2f213b5c148073 (diff) |
fix: consolidate path delimiter logic
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/commands/bin.js | 62 | ||||
-rw-r--r-- | test/lib/commands/exec.js | 8 | ||||
-rw-r--r-- | test/lib/utils/path.js | 13 |
3 files changed, 20 insertions, 63 deletions
diff --git a/test/lib/commands/bin.js b/test/lib/commands/bin.js index a889b1336..46170e765 100644 --- a/test/lib/commands/bin.js +++ b/test/lib/commands/bin.js @@ -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)']]) }) diff --git a/test/lib/commands/exec.js b/test/lib/commands/exec.js index 3c75c1d8d..1f7230d25 100644 --- a/test/lib/commands/exec.js +++ b/test/lib/commands/exec.js @@ -72,8 +72,6 @@ const read = (options, cb) => { process.nextTick(() => cb(READ_ERROR, READ_RESULT)) } -const PATH = require('../../../lib/utils/path.js') - let CI_NAME = 'travis-ci' const log = { @@ -154,7 +152,7 @@ t.test('npx foo, bin already exists locally', async t => { stdioString: true, event: 'npx', env: { - PATH: [npm.localBin, ...PATH].join(delimiter), + PATH: [npm.localBin, process.env.PATH].join(delimiter), }, stdio: 'inherit', }, @@ -183,7 +181,7 @@ t.test('npx foo, bin already exists globally', async t => { stdioString: true, event: 'npx', env: { - PATH: [npm.globalBin, ...PATH].join(delimiter), + PATH: [npm.globalBin, process.env.PATH].join(delimiter), }, stdio: 'inherit', }, @@ -1175,7 +1173,7 @@ t.test('workspaces', t => { stdioString: true, event: 'npx', env: { - PATH: [npm.localBin, ...PATH].join(delimiter), + PATH: [npm.localBin, process.env.PATH].join(delimiter), }, stdio: 'inherit', }, diff --git a/test/lib/utils/path.js b/test/lib/utils/path.js deleted file mode 100644 index b3bb269f3..000000000 --- a/test/lib/utils/path.js +++ /dev/null @@ -1,13 +0,0 @@ -const t = require('tap') -const mod = '../../../lib/utils/path.js' -const { isWindows } = require('../../../lib/utils/is-windows.js') -const delim = isWindows ? ';' : ':' -Object.defineProperty(process, 'env', { - value: {}, -}) -process.env.path = ['foo', 'bar', 'baz'].join(delim) -t.strictSame(t.mock(mod), ['foo', 'bar', 'baz']) -process.env.Path = ['a', 'b', 'c'].join(delim) -t.strictSame(t.mock(mod), ['a', 'b', 'c']) -process.env.PATH = ['x', 'y', 'z'].join(delim) -t.strictSame(t.mock(mod), ['x', 'y', 'z']) |