bdd-stdin
bdd-stdin copied to clipboard
Race condition when using Inquirer.js
Running the code below sometimes works and sometimes doesn't.
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?
seems like this is a race condition that I did not prepare for. If you could come up with a self-contained unit tests, that would be great to merge in and fix.
@bahmutov Thanks for the response, are you suggesting a self-contained unit test involving Inquirer
?
yeah, if possible, otherwise it is hard to debug this
The pr is ready to fire, but I just realized that the issue is already present in your checkbox-spec.js
spec. Just upgrade your inquirer
dependency to v1 and it'll surface. Let me know if you want me to pr either way.