I am curious how you are supposed to set a timeout for a function that returns a callback, if the callback is never fired, the promise will never resolve.
const mockCliAsync = (argv, stdio, timeout) => {
return new Promise((resolve, reject) => {
let timedout = false
const timeoutTimer = setTimeout(() => {
timedout = true
kill()
return reject(new Error('timeout'))
}, timeout)
const kill = mockCli(argv, stdio, (error, result) => {
if (!timedout) {
clearTimeout(timeoutTimer)
if (error) return reject(error)
return resolve(result)
}
})
})
}