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

fix: pause prompt stdin #36

Merged
merged 7 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ function normal(options: IPromptConfig, retries = 100): Promise<string> {
resolve(data || options.default)
}
})
if (options.timeout) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason you removed this conditional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it in to fix this issue: heroku/cli#880

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge mistake, putting it back

setTimeout(() => reject(new Error('timed out')), options.timeout).unref()
}
setTimeout(() => {
process.stdin.pause()
reject(new Error('Prompt timeout'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not having an error object in reject was causing issues later in oclif/config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that's something TypeScript should enforce (possibly behind a flag)

}, options.timeout || 10000).unref()
})
}
2 changes: 2 additions & 0 deletions test/prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ describe('prompt', () => {
await expect(cli.prompt('Require input?', {timeout: 1}))
.to.eventually.be.rejectedWith('timed out')
})
.catch('Prompt timeout')
.end('timeouts with no input')
})