Skip to content

Commit

Permalink
test: add test case for exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSTL committed Dec 13, 2020
1 parent 902e8b9 commit 6022f6a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/fixtures/cliExitCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const enquirer = require("enquirer");

const choices = ["0", "1", "2", "3"];

enquirer
.prompt({
type: "select",
name: "exitCode",
message: "Pick the exit code",
choices,
})
.then(({ exitCode }) => {
console.log(`You chose ${exitCode} exit code`);
process.exit(exitCode);
});
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ENTER = "\x0D";
const SPACE = "\x20";

const cliPath = `${__dirname}/fixtures/cli.js`;
const cliExitCodePath = `${__dirname}/fixtures/cliExitCode.js`;

describe("cli-prompts-test", () => {
it("picks a single option", async () => {
Expand All @@ -26,4 +27,17 @@ describe("cli-prompts-test", () => {
expect(exitCode).toBe(0);
expect(stdout).toContain("You chose aqua, fuchsia, green");
});

it("pick 0 exit code options", async () => {
const { exitCode } = await runTest([cliExitCodePath], [ENTER]);
expect(exitCode).toBe(0);
});

it("pick 2 exit code options", async () => {
const { exitCode } = await runTest(
[cliExitCodePath],
[`${DOWN}${DOWN}${ENTER}`]
);
expect(exitCode).toBe(2);
});
});

0 comments on commit 6022f6a

Please sign in to comment.