diff --git a/test/e2e/cli.test.js b/test/e2e/cli.test.js index a5adee13..ccc31297 100644 --- a/test/e2e/cli.test.js +++ b/test/e2e/cli.test.js @@ -96,6 +96,17 @@ it('generate exits 1 when the default config has malformed JSON', async ({ expect(result.stderr).not.toContain('at readConfigFile'); }); +it('bare command waits on the prompt', async ({ project }) => { + const result = await runCli([], { + cwd: project, + timeout: 5000, + waitFor: 'What do you want to do?', + }); + + expect(result.killed).toBe(true); + expect(result.stdout).toContain('What do you want to do?'); +}); + it('exits 1 for an unknown command', async ({ tmpDir }) => { const result = await runCli(['nope'], { cwd: tmpDir }); diff --git a/test/e2e/run-cli.js b/test/e2e/run-cli.js index fba2c740..52b2b6c3 100644 --- a/test/e2e/run-cli.js +++ b/test/e2e/run-cli.js @@ -14,11 +14,30 @@ export async function runGit(args, { cwd }) { } // Runs the CLI and returns the code, stdout, and stderr. -export function runCli(args, { cwd = process.cwd() } = {}) { +export function runCli(args, { cwd = process.cwd(), timeout = 0, waitFor } = {}) { return new Promise((resolve) => { // run the CLI - execFile(process.execPath, [cliPath, ...args], { cwd }, (error, stdout, stderr) => { - resolve({ code: error ? error.code : 0, stdout, stderr }); - }); + const child = execFile( + process.execPath, + [cliPath, ...args], + { cwd, timeout }, + (error, stdout, stderr) => { + resolve({ + code: error ? error.code : 0, + stdout, + stderr, + killed: Boolean(error?.killed), + }); + }, + ); + + // stop the CLI once stdout contains `waitFor` + if (waitFor) { + let output = ''; + child.stdout.on('data', (chunk) => { + output += chunk; + if (output.includes(waitFor)) child.kill(); + }); + } }); }