Skip to content

Commit

Permalink
fix(jest-dev-server): fix watch mode stdin after ask
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Jun 17, 2018
1 parent 4174526 commit a7ca57b
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/jest-dev-server/src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ function runServer(config = {}) {
}
}

async function outOfStin(block) {
const { stdin } = process
const listeners = stdin.listeners('data')
const result = await block()
listeners.forEach(listener => stdin.on('data', listener))
stdin.setRawMode(true)
stdin.setEncoding('utf8')
stdin.resume()
return result
}

export async function setup(config) {
config = { ...DEFAULT_CONFIG, ...config }

Expand Down Expand Up @@ -101,14 +112,16 @@ export async function setup(config) {
case 'ask': {
console.log('')
logProcDetection(portProcess, config.port)
const answers = await inquirer.prompt([
{
type: 'confirm',
name: 'kill',
message: 'Should I kill it for you?',
default: true,
},
])
const answers = await outOfStin(() =>
inquirer.prompt([
{
type: 'confirm',
name: 'kill',
message: 'Should I kill it for you?',
default: true,
},
]),
)
if (answers.kill) {
await killProc(portProcess)
} else {
Expand Down

0 comments on commit a7ca57b

Please sign in to comment.