Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/e2e/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
27 changes: 23 additions & 4 deletions test/e2e/run-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
});
}
Loading