Skip to content

Commit

Permalink
fixup! fix the tests too
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Nov 10, 2021
1 parent 5f6beb8 commit 6576f29
Show file tree
Hide file tree
Showing 4 changed files with 452 additions and 538 deletions.
1 change: 1 addition & 0 deletions lib/commands/access.js
Expand Up @@ -74,6 +74,7 @@ class Access extends BaseCommand {
case 'revoke':
return []
default:
console.log('throwing')
throw new Error(argv[2] + ' not recognized')
}
}
Expand Down
13 changes: 4 additions & 9 deletions lib/commands/completion.js
Expand Up @@ -180,12 +180,10 @@ class Completion extends BaseCommand {
// Ie, returning ['a', 'b c', ['d', 'e']] would allow it to expand
// to: 'a', 'b c', or 'd' 'e'
wrap (opts, compls) {
if (!Array.isArray(compls)) {
compls = compls ? [compls] : []
}

compls = compls.map(c =>
Array.isArray(c) ? c.map(escape).join(' ') : escape(c))
// TODO this was dead code, leaving it in case we find some command we
// forgot that requires this. if so *that command should fix its
// completions*
// compls = compls.map(w => !/\s+/.test(w) ? w : '\'' + w + '\'')

if (opts.partialWord) {
compls = compls.filter(c => c.startsWith(opts.partialWord))
Expand Down Expand Up @@ -246,9 +244,6 @@ const dumpScript = async () => {
const unescape = w => w.charAt(0) === '\'' ? w.replace(/^'|'$/g, '')
: w.replace(/\\ /g, ' ')

const escape = w => !/\s+/.test(w) ? w
: '\'' + w + '\''

// the current word has a dash. Return the config names,
// with the same number of dashes as the current word has.
const configCompl = opts => {
Expand Down
239 changes: 239 additions & 0 deletions tap-snapshots/test/lib/commands/completion.js.test.cjs
@@ -0,0 +1,239 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/lib/commands/completion.js TAP completion --no- flags > flags 1`] = `
Array [
Array [
String(
--no-version
--no-versions
),
],
]
`

exports[`test/lib/commands/completion.js TAP completion commands with no completion > no results 1`] = `
Array []
`

exports[`test/lib/commands/completion.js TAP completion completion cannot complete options that take a value in mid-command > does not try to complete option arguments in the middle of a command 1`] = `
Array []
`

exports[`test/lib/commands/completion.js TAP completion completion completion > both shells 1`] = `
Array []
`

exports[`test/lib/commands/completion.js TAP completion completion completion no known shells > no responses 1`] = `
Array []
`

exports[`test/lib/commands/completion.js TAP completion completion completion wrong word count > no responses 1`] = `
Array []
`

exports[`test/lib/commands/completion.js TAP completion completion of invalid command name does nothing > no results 1`] = `
Array []
`

exports[`test/lib/commands/completion.js TAP completion double dashes escape from flag completion > full command list 1`] = `
Array [
Array [
String(
ci
install-ci-test
install
install-test
uninstall
cache
config
set
get
update
outdated
prune
pack
find-dupes
dedupe
hook
rebuild
link
publish
star
stars
unstar
adduser
login
logout
unpublish
owner
access
team
deprecate
shrinkwrap
token
profile
audit
fund
org
help
ls
ll
search
view
init
version
edit
explore
docs
repo
bugs
root
prefix
bin
whoami
diff
dist-tag
ping
pkg
test
stop
start
restart
run-script
set-script
completion
doctor
exec
explain
un
rb
list
ln
create
i
it
cit
up
c
s
se
tst
t
ddp
v
run
clean-install
clean-install-test
x
why
la
verison
ic
innit
in
ins
inst
insta
instal
isnt
isnta
isntal
install-clean
isntall-clean
hlep
dist-tags
upgrade
udpate
login
add-user
author
home
issues
info
show
find
add
unlink
remove
rm
r
rum
sit
urn
ogr
),
],
]
`

exports[`test/lib/commands/completion.js TAP completion filtered subcommands > filtered subcommands 1`] = `
Array [
Array [
"public",
],
]
`

exports[`test/lib/commands/completion.js TAP completion flags > flags 1`] = `
Array [
Array [
String(
--version
--versions
--viewer
--verbose
--v
),
],
]
`

exports[`test/lib/commands/completion.js TAP completion multiple command names > multiple command names 1`] = `
Array [
Array [
String(
adduser
access
audit
add-user
author
add
),
],
]
`

exports[`test/lib/commands/completion.js TAP completion single command name > single command name 1`] = `
Array [
Array [
"config",
],
]
`

exports[`test/lib/commands/completion.js TAP completion subcommand completion > subcommands 1`] = `
Array [
Array [
String(
public
restricted
grant
revoke
ls-packages
ls-collaborators
edit
2fa-required
2fa-not-required
),
],
]
`

exports[`test/lib/commands/completion.js TAP windows without bash > no output 1`] = `
Array []
`

0 comments on commit 6576f29

Please sign in to comment.