tony-go / clix

Write acceptance tests easily for your CLI program.
21 stars 2 forks source link

feat: add `.select` API #16

Open tony-go opened 2 years ago

tony-go commented 2 years ago

Context

In some cases, CLI tools outputs list of choice:

How are you?
- bad
- so bad
- so so so bad

We'd like to have an API to simulate check list input:

const scenario_3 = clix('my command')
  .expect([ // Handle multiple lines with arrays
    'What is your choice?',
    /a/,
    /b/
  ])
  .select([1]) // using an array for multiple choices
  .expect('Ok, dude!');

const { ok } = await scenario_3.run();
assert.ok(ok);

Acceptance criteria

tony-go commented 2 years ago

We didn't benefit from a straightforward way to happen keystroke directly to the stdin... (look at https://github.com/nodejs/node/issues/43137)

In my former investigation 👀 I've found a package called xdotool. I'll consider writing a POC with it, but maybe we'll have to revamp the whole project. 🙇‍♂️