is there a programmatic api for interacting with stdout and stdin? I'm wanting to write some tests for some cli tools
I've had a hard time ascertaining how to do this from the readme, and could use some help, but I imagine something like this:
a utility I may have:
```ts
export function cli(args: string[] = []) {
let cmd = `node ${cliPath} ${args.join(" ")}`;
console.log(`Running '${styleText("cyan", cmd)}'`);
let output = new MockWritable();
let input = new MockReadable();
let execaPromise = execa("node", args, { shell: true, stdout: output, stdin: input });
return {
execaPromise,
output,
input,
};
}
```
and then usage:
```js
let { output, input } = cli('...')
// runs until user is prompted
await output.next();
if (output.text.last.includes("Confirm?")) {
// confirm a prompt
input.type('[Enter]');
}
await output.next();
```
idk 🤷
I've never really found good CLI testing tools before, so I'm open to whatever
2 条评论