diff options
author | isaacs <i@izs.me> | 2020-08-01 01:01:45 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-08-04 11:03:20 +0300 |
commit | 3aba8d62f060753a089e7108130624722d32453a (patch) | |
tree | b19baed33b9f2fec26a9eaef6c77fb03a6774d7d /test/bin | |
parent | 87d27d389065609e94ee218ab001972fc0041fe9 (diff) |
npx: add install prompt, handle options correctly
- handle previous npx options that are still possible to be handled, and
print a warning if any deprecated/removed options are used.
- expand shorthands properly in npx command line.
- take existing npm options into account when determining placement of
the -- argument.
- document changes from previous versions of npx.
PR-URL: https://github.com/npm/cli/pull/1596
Credit: @isaacs
Close: #1596
Reviewed-by: @ruyadorno
Diffstat (limited to 'test/bin')
-rw-r--r-- | test/bin/npx-cli.js | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/test/bin/npx-cli.js b/test/bin/npx-cli.js index 8995fb76a..fc85f6366 100644 --- a/test/bin/npx-cli.js +++ b/test/bin/npx-cli.js @@ -4,6 +4,14 @@ const npx = require.resolve('../../bin/npx-cli.js') const cli = require.resolve('../../lib/cli.js') const npm = require.resolve('../../bin/npm-cli.js') +const logs = [] +console.error = (...msg) => logs.push(msg) + +t.afterEach(cb => { + logs.length = 0 + cb() +}) + t.test('npx foo -> npm exec -- foo', t => { process.argv = ['node', npx, 'foo'] requireInject(npx, { [cli]: () => {} }) @@ -25,9 +33,63 @@ t.test('npx -x y foo -z -> npm exec -x y -- foo -z', t => { t.end() }) -t.test('npx --x=y foo -z -> npm exec --x=y -- foo -z', t => { - process.argv = ['node', npx, '--x=y', 'foo', '-z'] +t.test('npx --x=y --no-install foo -z -> npm exec --x=y -- foo -z', t => { + process.argv = ['node', npx, '--x=y', '--no-install', 'foo', '-z'] + requireInject(npx, { [cli]: () => {} }) + t.strictSame(process.argv, ['node', npm, 'exec', '--x=y', '--yes=false', '--', 'foo', '-z']) + t.end() +}) + +t.test('transform renamed options into proper values', t => { + process.argv = ['node', npx, '-y', '--shell=bash', '-p', 'foo', '-c', 'asdf'] + requireInject(npx, { [cli]: () => {} }) + t.strictSame(process.argv, ['node', npm, 'exec', '--yes', '--script-shell=bash', '--package', 'foo', '--call', 'asdf']) + t.end() +}) + +// warn if deprecated switches/options are used +t.test('use a bunch of deprecated switches and options', t => { + process.argv = [ + 'node', + npx, + '--npm', + '/some/npm/bin', + '--node-arg=--harmony', + '-n', + '--require=foobar', + '--reg=http://localhost:12345/', + '-p', + 'foo', + '--always-spawn', + '--shell-auto-fallback', + '--ignore-existing', + '-q', + 'foobar' + ] + + const expect = [ + 'node', + npm, + 'exec', + '--registry', + 'http://localhost:12345/', + '--package', + 'foo', + '--loglevel', + 'warn', + '--', + 'foobar' + ] requireInject(npx, { [cli]: () => {} }) - t.strictSame(process.argv, ['node', npm, 'exec', '--x=y', '--', 'foo', '-z']) + t.strictSame(process.argv, expect) + t.strictSame(logs, [ + [ 'npx: the --npm argument has been removed.' ], + [ 'npx: the --node-arg argument has been removed.' ], + [ 'npx: the --n argument has been removed.' ], + [ 'npx: the --always-spawn argument has been removed.' ], + [ 'npx: the --shell-auto-fallback argument has been removed.' ], + [ 'npx: the --ignore-existing argument has been removed.' ], + [ 'See `npm help exec` for more information' ] + ]) t.end() }) |