You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?')
The text was updated successfully, but these errors were encountered:
A lot of CLI commands follow the Unix philosophy and read
stdin
for default input and write output tostdout
by default.cli-testing-library
already makes it easy to test the latter case as theexecute
API provides accessstdout
andstderr
. But to test a simple CLI command that readsstdin
, one is forced to use thespawn
API. This is ok, but it would very nice if an optionalstdin: string
parameter were supported as follows: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.:Another alternative:
The text was updated successfully, but these errors were encountered: