Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
fix: ensure ansi-escapes is added
Browse files Browse the repository at this point in the history
also updated linter

Fixes #51
  • Loading branch information
jdx committed Sep 13, 2018
1 parent 9315ce3 commit ed4038f
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 179 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@oclif/errors": "^1.2.0",
"@oclif/linewrap": "^1.0.0",
"@oclif/screen": "^1.0.2",
"ansi-escapes": "^3.1.0",
"ansi-styles": "^3.2.1",
"cardinal": "^2.1.1",
"chalk": "^2.4.1",
Expand All @@ -17,15 +18,15 @@
"hyperlinker": "^1.0.0",
"indent-string": "^3.2.0",
"is-wsl": "^1.1.0",
"lodash": "^4.17.10",
"lodash": "^4.17.11",
"password-prompt": "^1.0.7",
"semver": "^5.5.1",
"strip-ansi": "^4.0.0",
"supports-color": "^5.5.0",
"supports-hyperlinks": "^1.0.1"
},
"devDependencies": {
"@oclif/tslint": "^2.0.0",
"@oclif/tslint": "^3.1.0",
"@types/ansi-styles": "^3.2.0",
"@types/chai": "^4.1.4",
"@types/chai-as-promised": "^7.1.0",
Expand All @@ -35,20 +36,20 @@
"@types/indent-string": "^3.0.0",
"@types/lodash": "^4.14.116",
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.1",
"@types/node": "^10.9.4",
"@types/semver": "^5.5.0",
"@types/strip-ansi": "^3.0.0",
"@types/supports-color": "^5.3.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"eslint": "^5.4.0",
"eslint": "^5.5.0",
"eslint-config-oclif": "^3.0.0",
"fancy-test": "^1.3.0",
"fancy-test": "^1.4.0",
"husky": "^0.14.3",
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.0.1"
"typescript": "^3.0.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down
18 changes: 9 additions & 9 deletions src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ function _prompt(name: string, inputOptions: Partial<IPromptOptions> = {}): Prom
...inputOptions,
}
switch (options.type) {
case 'normal':
return normal(options)
case 'single':
return single(options)
case 'mask':
case 'hide':
return deps.passwordPrompt(options.prompt, {method: options.type})
default:
throw new Error(`unexpected type ${options.type}`)
case 'normal':
return normal(options)
case 'single':
return single(options)
case 'mask':
case 'hide':
return deps.passwordPrompt(options.prompt, {method: options.type})
default:
throw new Error(`unexpected type ${options.type}`)
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ process.env.FORCE_HYPERLINK = '1'

describe('prompt', () => {
fancy
.stdout()
.do(() => ux.url('sometext', 'https://google.com'))
.it('renders hyperlink', async ({stdout}) => {
expect(stdout).to.equal('ttps://google.com\u0007sometext\n')
})
.stdout()
.do(() => ux.url('sometext', 'https://google.com'))
.it('renders hyperlink', async ({stdout}) => {
expect(stdout).to.equal('ttps://google.com\u0007sometext\n')
})
})
94 changes: 47 additions & 47 deletions test/prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,68 @@ import {fancy} from './fancy'

describe('prompt', () => {
fancy
.stdout()
.stderr()
.end('requires input', async () => {
const promptPromise = cli.prompt('Require input?')
process.stdin.emit('data', '')
process.stdin.emit('data', 'answer')
const answer = await promptPromise
await cli.done()
expect(answer).to.equal('answer')
})
.stdout()
.stderr()
.end('requires input', async () => {
const promptPromise = cli.prompt('Require input?')
process.stdin.emit('data', '')
process.stdin.emit('data', 'answer')
const answer = await promptPromise
await cli.done()
expect(answer).to.equal('answer')
})

fancy
.stdout()
.stderr()
.stdin('y')
.end('confirm', async () => {
const promptPromise = cli.confirm('yes/no?')
const answer = await promptPromise
await cli.done()
expect(answer).to.equal(true)
})
.stdout()
.stderr()
.stdin('y')
.end('confirm', async () => {
const promptPromise = cli.confirm('yes/no?')
const answer = await promptPromise
await cli.done()
expect(answer).to.equal(true)
})

fancy
.stdout()
.stderr()
.stdin('n')
.end('confirm', async () => {
const promptPromise = cli.confirm('yes/no?')
const answer = await promptPromise
await cli.done()
expect(answer).to.equal(false)
})
.stdout()
.stderr()
.stdin('n')
.end('confirm', async () => {
const promptPromise = cli.confirm('yes/no?')
const answer = await promptPromise
await cli.done()
expect(answer).to.equal(false)
})

fancy
.stdout()
.stderr()
.stdin('x')
.end('gets anykey', async () => {
const promptPromise = cli.anykey()
const answer = await promptPromise
await cli.done()
expect(answer).to.equal('x')
})
.stdout()
.stderr()
.stdin('x')
.end('gets anykey', async () => {
const promptPromise = cli.anykey()
const answer = await promptPromise
await cli.done()
expect(answer).to.equal('x')
})

fancy
.stdout()
.stderr()
.end('does not require input', async () => {
.stdout()
.stderr()
.end('does not require input', async () => {
const promptPromise = cli.prompt('Require input?', {
required: false
})
process.stdin.emit('data', '')
const answer = await promptPromise
await cli.done()
expect(answer).to.equal(undefined)
})
})

fancy
.stdout()
.stderr()
.it('timeouts with no input', async () => {
await expect(cli.prompt('Require input?', {timeout: 1}))
.to.eventually.be.rejectedWith('Prompt timeout')
})
.stdout()
.stderr()
.it('timeouts with no input', async () => {
await expect(cli.prompt('Require input?', {timeout: 1}))
.to.eventually.be.rejectedWith('Prompt timeout')
})
})
12 changes: 6 additions & 6 deletions test/styled/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import cli from '../../src'

describe('styled/table', () => {
fancy
.stdout()
.end('shows a table', output => {
cli.styledObject([
.stdout()
.end('shows a table', output => {
cli.styledObject([
{foo: 1, bar: 1},
{foo: 2, bar: 2},
{foo: 3, bar: 3},
])
expect(output.stdout).to.equal(`0: foo: 1, bar: 1
])
expect(output.stdout).to.equal(`0: foo: 1, bar: 1
1: foo: 2, bar: 2
2: foo: 3, bar: 3
`)
})
})
})
38 changes: 19 additions & 19 deletions test/styled/table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ import cli from '../../src'

describe('styled/table', () => {
fancy
.stdout()
.end('shows a table', output => {
cli.table([
.stdout()
.end('shows a table', output => {
cli.table([
{foo: 1, bar: 1},
{foo: 2, bar: 2},
{foo: 3, bar: 3},
], {
columns: [
], {
columns: [
{key: 'bar'},
{key: 'foo'},
]
})
expect(output.stdout).to.equal(`bar foo
]
})
expect(output.stdout).to.equal(`bar foo
─── ───
1 1
2 2
3 3
`)
})
})

fancy
.stdout()
.end('hides the header', output => {
cli.table([
.stdout()
.end('hides the header', output => {
cli.table([
{foo: 1, bar: 1},
{foo: 2, bar: 2},
{foo: 3, bar: 3},
], {
printHeader: undefined,
columns: [
], {
printHeader: undefined,
columns: [
{key: 'bar'},
{key: 'foo'},
]
})
]
})

expect(output.stdout).to.equal(`1 1
expect(output.stdout).to.equal(`1 1
2 2
3 3
`)
})
})
})
Loading

0 comments on commit ed4038f

Please sign in to comment.