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

What is the recommended way to test cliffy cli ap? #778

Open
maxkoretskyi opened this issue Dec 31, 2024 · 0 comments
Open

What is the recommended way to test cliffy cli ap? #778

maxkoretskyi opened this issue Dec 31, 2024 · 0 comments

Comments

@maxkoretskyi
Copy link

maxkoretskyi commented Dec 31, 2024

Let's say I have this very basic command:

async function setupSMPT() {
  let smtpUsername = "NA";
  let smtpPassword = "NA";

  const confirm = await Confirm.prompt(
    "Do you want to setup a connection with a SMTP server?",
  );

  if (confirm) {
    smtpUsername = await Input.prompt(
      "Please specify the username to connect to your SMTP server:",
    );
    smtpPassword = await Input.prompt(
      "Please specify the password to connect to your SMTP server:",
    );
  }

  return { smtpUsername, smtpPassword };
}

const smtp = new Command()
  .name("smtp")
  .option(
    "--interactive [interactive:boolean]",
    "Enable or disable interactive mode.",
    { default: true },
  )
  .action(setupSMPT)

await new Command()
  .name("root")
  .command("smtp", smtp)
  .parse(Deno.args);

How can I test it? Basically, it's 2 sub-tasks I need to do:

  1. Provide a stub for promps used in the action function. Is there a helper for this?
  2. Run the command either as a subprocess with Deno.run/spawnChild or directly calling an action function setupSMPT({...})

Any help is appreciated!

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