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 all 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
5 changes: 4 additions & 1 deletion src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ function normal(options: IPromptConfig, retries = 100): Promise<string> {
}
})
if (options.timeout) {
setTimeout(() => reject(new Error('timed out')), options.timeout).unref()
setTimeout(() => {
process.stdin.pause()
reject(new Error('Prompt timeout'))
}, options.timeout).unref()
}
})
}
4 changes: 2 additions & 2 deletions test/prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ describe('prompt', () => {
fancy
.stdout()
.stderr()
.end('timeouts with no input', async () => {
.it('timeouts with no input', async () => {
await expect(cli.prompt('Require input?', {timeout: 1}))
.to.eventually.be.rejectedWith('timed out')
.to.eventually.be.rejectedWith('Prompt timeout')
})
})