Skip to content

Commit

Permalink
fixup! minor cleanup of completion command and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Dec 9, 2020
1 parent 3d6cea6 commit 22766d6
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions test/lib/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { test } = require('tap')
const requireInject = require('require-inject')
const fs = require('fs')
const path = require('path')
const isWindowsShell = require('../../lib/utils/is-windows-shell.js')

const completionScript = fs.readFileSync(path.resolve(__dirname, '../../lib/utils/completion.sh'), { encoding: 'utf8' }).replace(/^#!.*?\n/, '')

Expand Down Expand Up @@ -85,7 +86,7 @@ const completion = requireInject('../../lib/completion.js', {
},
})

test('completion completion', t => {
test('completion completion', { skip: isWindowsShell }, t => {
const home = process.env.HOME
t.teardown(() => {
process.env.HOME = home
Expand All @@ -108,7 +109,7 @@ test('completion completion', t => {
})
})

test('completion completion no known shells', t => {
test('completion completion no known shells', { skip: isWindowsShell }, t => {
const home = process.env.HOME
t.teardown(() => {
process.env.HOME = home
Expand All @@ -125,7 +126,7 @@ test('completion completion no known shells', t => {
})
})

test('completion completion wrong word count', t => {
test('completion completion wrong word count', { skip: isWindowsShell }, t => {
completion.completion({ w: 3 }, (err, res) => {
if (err)
throw err
Expand All @@ -149,7 +150,7 @@ test('completion errors in windows without bash', t => {
})
})

test('dump script when completion is not being attempted', t => {
test('dump script when completion is not being attempted', { skip: isWindowsShell }, t => {
const _write = process.stdout.write
const _on = process.stdout.on
t.teardown(() => {
Expand Down Expand Up @@ -182,7 +183,7 @@ test('dump script when completion is not being attempted', t => {
})
})

test('dump script exits correctly when EPIPE is emitted on stdout', t => {
test('dump script exits correctly when EPIPE is emitted on stdout', { skip: isWindowsShell }, t => {
const _write = process.stdout.write
const _on = process.stdout.on
t.teardown(() => {
Expand Down Expand Up @@ -215,7 +216,7 @@ test('dump script exits correctly when EPIPE is emitted on stdout', t => {
})
})

test('non EPIPE errors cause failures', t => {
test('non EPIPE errors cause failures', { skip: isWindowsShell }, t => {
const _write = process.stdout.write
const _on = process.stdout.on
t.teardown(() => {
Expand Down Expand Up @@ -246,7 +247,7 @@ test('non EPIPE errors cause failures', t => {
})
})

test('completion completes single command name', t => {
test('completion completes single command name', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 1
process.env.COMP_LINE = 'npm c'
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand All @@ -268,7 +269,7 @@ test('completion completes single command name', t => {
})
})

test('completion completes command names', t => {
test('completion completes command names', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 1
process.env.COMP_LINE = 'npm a'
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand All @@ -290,7 +291,7 @@ test('completion completes command names', t => {
})
})

test('completion of invalid command name does nothing', t => {
test('completion of invalid command name does nothing', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 1
process.env.COMP_LINE = 'npm compute'
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand All @@ -312,7 +313,7 @@ test('completion of invalid command name does nothing', t => {
})
})

test('completion triggers command completions', t => {
test('completion triggers command completions', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm access '
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand Down Expand Up @@ -341,7 +342,7 @@ test('completion triggers command completions', t => {
})
})

test('completion triggers filtered command completions', t => {
test('completion triggers filtered command completions', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm access p'
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand Down Expand Up @@ -370,7 +371,7 @@ test('completion triggers filtered command completions', t => {
})
})

test('completions for commands that return nested arrays are joined', t => {
test('completions for commands that return nested arrays are joined', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm completion '
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand Down Expand Up @@ -399,7 +400,7 @@ test('completions for commands that return nested arrays are joined', t => {
})
})

test('completions for commands that return nothing work correctly', t => {
test('completions for commands that return nothing work correctly', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm donothing '
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand Down Expand Up @@ -428,7 +429,7 @@ test('completions for commands that return nothing work correctly', t => {
})
})

test('completions for commands that return a single item work correctly', t => {
test('completions for commands that return a single item work correctly', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm driveaboat '
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand Down Expand Up @@ -457,7 +458,7 @@ test('completions for commands that return a single item work correctly', t => {
})
})

test('command completion for commands with no completion return no results', t => {
test('command completion for commands with no completion return no results', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm adduser '
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand Down Expand Up @@ -487,7 +488,7 @@ test('command completion for commands with no completion return no results', t =
})
})

test('command completion errors propagate', t => {
test('command completion errors propagate', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm access '
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand Down Expand Up @@ -516,7 +517,7 @@ test('command completion errors propagate', t => {
})
})

test('completion can complete flags', t => {
test('completion can complete flags', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm install --'
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand All @@ -539,7 +540,7 @@ test('completion can complete flags', t => {
})
})

test('double dashes escape from flag completion', t => {
test('double dashes escape from flag completion', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm -- install --'
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand All @@ -562,7 +563,7 @@ test('double dashes escape from flag completion', t => {
})
})

test('completion cannot complete options that take a value in mid-command', t => {
test('completion cannot complete options that take a value in mid-command', { skip: isWindowsShell }, t => {
process.env.COMP_CWORD = 2
process.env.COMP_LINE = 'npm --registry install'
process.env.COMP_POINT = process.env.COMP_LINE.length
Expand Down

0 comments on commit 22766d6

Please sign in to comment.