bahmutov / bahmutov/bdd-stdin

Race condition when using Inquirer.js

Open
#2 4 comments 0 reactions 0 assignees View on GitHub
bug question
Dominant language
JavaScript
Stars
38
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Running the code below sometimes works and sometimes doesn't.

``` js
BDDStdin('hello\n', 'hello\n')
const questions = [{
type: 'input',
name: 'projectName',
message: 'What\'s the name of your project?',
default: function () {
return 'hey'
}
},
{
type: 'input',
name: 'projectName2',
message: 'What\'s the name of your project again?',
default: function () {
return 'hey2'
}
}
]
const prompt = Inquirer.prompt(questions)
prompt.then(answers => {
expect(answers.projectName).toBe('hey')
expect(answers.projectName2).toBe('hey2')
done()
})
```

It seems like `bdd-stdin` doesn't quite know when the question shows up. Not sure if it's an interference of some sort with Inquire.js or a bug, but changing https://github.com/bahmutov/bdd-stdin/blob/master/index.js#L31 to something like `500` makes everything okay (at least as far as I have witnessed). Any suggestions on how this could be sustainably resolved?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the provided Inquirer.js snippet and inspect index.js around line 31, where increasing the delay appears to affect the result. Trace when bdd-stdin supplies input relative to question display; done means both answers are consistently returned without relying on an arbitrary long timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.