Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: add an optional stdin: string parameter to execute #4

Open
vassudanagunta opened this issue Aug 19, 2022 · 0 comments
Open

FEAT: add an optional stdin: string parameter to execute #4

vassudanagunta opened this issue Aug 19, 2022 · 0 comments

Comments

@vassudanagunta
Copy link

A lot of CLI commands follow the Unix philosophy and read stdin for default input and write output to stdout by default.

cli-testing-library already makes it easy to test the latter case as the execute API provides access stdout and stderr. But to test a simple CLI command that reads stdin, one is forced to use the spawn API. This is ok, but it would very nice if an optional stdin: string parameter were supported as follows:

it('program runs successfully', async () => {
    const { execute, cleanup } = await prepareEnvironment()
    const { code, stdout, stderr } = await execute(
        'node',
        './cli.js',
        'Hello? (Hello, hello, hello) / Is there anybody in there?'
    )
    expect(stdout).toBe(['Just nod if you can hear me / Is there anyone home?'])
    await cleanup()
});

I know this would clash with the existing optional runFrom parameter. Since your are in early alpha now might be a good time to switch a different way for users to pass in optional params, e.g. an options object, e.g.:

const { code, stdout, stderr } = await execute(
    'node',
    './cli.js',
    {stdin: 'Hello? (Hello, hello, hello) / Is there anybody in there?',
     runFrom: './testContext'}
)

Another alternative:

const { code, stdin, stdout, stderr } = await execute(
    'node',
    './cli.js'
)

// writes to and immediately closes stdin:
stdin('Hello? (Hello, hello, hello) / Is there anybody in there?')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant