11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst mockGlobals = require('@npmcli/mock-globals') 31cb0ef41Sopenharmony_ciconst tmock = require('../fixtures/tmock') 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst npm = require.resolve('../../bin/npm-cli.js') 61cb0ef41Sopenharmony_ciconst npx = require.resolve('../../bin/npx-cli.js') 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst mockNpx = (t, argv) => { 91cb0ef41Sopenharmony_ci const logs = [] 101cb0ef41Sopenharmony_ci mockGlobals(t, { 111cb0ef41Sopenharmony_ci 'process.argv': argv, 121cb0ef41Sopenharmony_ci 'console.error': (...msg) => logs.push(msg), 131cb0ef41Sopenharmony_ci }) 141cb0ef41Sopenharmony_ci tmock(t, '{BIN}/npx-cli.js', { '{LIB}/cli.js': () => {} }) 151cb0ef41Sopenharmony_ci return { 161cb0ef41Sopenharmony_ci logs, 171cb0ef41Sopenharmony_ci argv: process.argv, 181cb0ef41Sopenharmony_ci } 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_cit.test('npx foo -> npm exec -- foo', async t => { 221cb0ef41Sopenharmony_ci const { argv } = mockNpx(t, ['node', npx, 'foo']) 231cb0ef41Sopenharmony_ci t.strictSame(argv, ['node', npm, 'exec', '--', 'foo']) 241cb0ef41Sopenharmony_ci}) 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cit.test('npx -- foo -> npm exec -- foo', async t => { 271cb0ef41Sopenharmony_ci const { argv } = mockNpx(t, ['node', npx, '--', 'foo']) 281cb0ef41Sopenharmony_ci t.strictSame(argv, ['node', npm, 'exec', '--', 'foo']) 291cb0ef41Sopenharmony_ci}) 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_cit.test('npx -x y foo -z -> npm exec -x y -- foo -z', async t => { 321cb0ef41Sopenharmony_ci const { argv } = mockNpx(t, ['node', npx, '-x', 'y', 'foo', '-z']) 331cb0ef41Sopenharmony_ci t.strictSame(argv, ['node', npm, 'exec', '-x', 'y', '--', 'foo', '-z']) 341cb0ef41Sopenharmony_ci}) 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_cit.test('npx --x=y --no-install foo -z -> npm exec --x=y -- foo -z', async t => { 371cb0ef41Sopenharmony_ci const { argv } = mockNpx(t, ['node', npx, '--x=y', '--no-install', 'foo', '-z']) 381cb0ef41Sopenharmony_ci t.strictSame(argv, ['node', npm, 'exec', '--x=y', '--yes=false', '--', 'foo', '-z']) 391cb0ef41Sopenharmony_ci}) 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_cit.test('transform renamed options into proper values', async t => { 421cb0ef41Sopenharmony_ci const { argv } = mockNpx(t, ['node', npx, '-y', '--shell=bash', '-p', 'foo', '-c', 'asdf']) 431cb0ef41Sopenharmony_ci t.strictSame(argv, [ 441cb0ef41Sopenharmony_ci 'node', 451cb0ef41Sopenharmony_ci npm, 461cb0ef41Sopenharmony_ci 'exec', 471cb0ef41Sopenharmony_ci '--yes', 481cb0ef41Sopenharmony_ci '--script-shell=bash', 491cb0ef41Sopenharmony_ci '--package', 501cb0ef41Sopenharmony_ci 'foo', 511cb0ef41Sopenharmony_ci '--call', 521cb0ef41Sopenharmony_ci 'asdf', 531cb0ef41Sopenharmony_ci ]) 541cb0ef41Sopenharmony_ci}) 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci// warn if deprecated switches/options are used 571cb0ef41Sopenharmony_cit.test('use a bunch of deprecated switches and options', async t => { 581cb0ef41Sopenharmony_ci const { argv, logs } = mockNpx(t, [ 591cb0ef41Sopenharmony_ci 'node', 601cb0ef41Sopenharmony_ci npx, 611cb0ef41Sopenharmony_ci '--npm', 621cb0ef41Sopenharmony_ci '/some/npm/bin', 631cb0ef41Sopenharmony_ci '--node-arg=--harmony', 641cb0ef41Sopenharmony_ci '-n', 651cb0ef41Sopenharmony_ci '--require=foobar', 661cb0ef41Sopenharmony_ci '--reg=http://localhost:12345/', 671cb0ef41Sopenharmony_ci '-p', 681cb0ef41Sopenharmony_ci 'foo', 691cb0ef41Sopenharmony_ci '--always-spawn', 701cb0ef41Sopenharmony_ci '--shell-auto-fallback', 711cb0ef41Sopenharmony_ci '--ignore-existing', 721cb0ef41Sopenharmony_ci '-q', 731cb0ef41Sopenharmony_ci 'foobar', 741cb0ef41Sopenharmony_ci ]) 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci const expect = [ 771cb0ef41Sopenharmony_ci 'node', 781cb0ef41Sopenharmony_ci npm, 791cb0ef41Sopenharmony_ci 'exec', 801cb0ef41Sopenharmony_ci '--registry', 811cb0ef41Sopenharmony_ci 'http://localhost:12345/', 821cb0ef41Sopenharmony_ci '--package', 831cb0ef41Sopenharmony_ci 'foo', 841cb0ef41Sopenharmony_ci '--loglevel', 851cb0ef41Sopenharmony_ci 'warn', 861cb0ef41Sopenharmony_ci '--', 871cb0ef41Sopenharmony_ci 'foobar', 881cb0ef41Sopenharmony_ci ] 891cb0ef41Sopenharmony_ci t.strictSame(argv, expect) 901cb0ef41Sopenharmony_ci t.strictSame(logs, [ 911cb0ef41Sopenharmony_ci ['npx: the --npm argument has been removed.'], 921cb0ef41Sopenharmony_ci ['npx: the --node-arg argument has been removed.'], 931cb0ef41Sopenharmony_ci ['npx: the --n argument has been removed.'], 941cb0ef41Sopenharmony_ci ['npx: the --always-spawn argument has been removed.'], 951cb0ef41Sopenharmony_ci ['npx: the --shell-auto-fallback argument has been removed.'], 961cb0ef41Sopenharmony_ci ['npx: the --ignore-existing argument has been removed.'], 971cb0ef41Sopenharmony_ci ['See `npm help exec` for more information'], 981cb0ef41Sopenharmony_ci ]) 991cb0ef41Sopenharmony_ci}) 100