-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
813269a
commit f101991
Showing
2 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const enquirer = require("enquirer"); | ||
|
||
enquirer | ||
.prompt({ | ||
type: "input", | ||
name: "text", | ||
message: "Please input some text", | ||
}) | ||
.then(({ text }) => { | ||
if (!text) { | ||
console.error("Invalid input"); | ||
process.exit(1); | ||
} | ||
console.log(text); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,57 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
|
||
const runTest = require("../"); | ||
|
||
const DOWN = "\x1B\x5B\x42"; | ||
const ENTER = "\x0D"; | ||
const SPACE = "\x20"; | ||
|
||
const cliPath = `${__dirname}/fixtures/cli.js`; | ||
const fixturesPath = path.join(__dirname, "fixtures"); | ||
const cliPath = path.join(fixturesPath, "cli.js"); | ||
const cliExitCodePath = path.join(fixturesPath, "cli-exit-code.js"); | ||
|
||
describe("cli-prompts-test", () => { | ||
it("picks a single option", async () => { | ||
const { stdout, exitCode } = await runTest( | ||
const { exitCode, stdout } = await runTest( | ||
[cliPath], | ||
[`${DOWN}${DOWN}${SPACE}${ENTER}`] | ||
); | ||
|
||
// Assertions | ||
expect(exitCode).toBe(0); | ||
expect(stdout).toContain("You chose blue"); | ||
}); | ||
|
||
it("picks multiple options", async () => { | ||
const { stdout, exitCode } = await runTest( | ||
const { exitCode, stdout } = await runTest( | ||
[cliPath], | ||
[`${SPACE}${DOWN}${DOWN}${DOWN}${SPACE}${ENTER}${DOWN}${SPACE}${ENTER}`] | ||
); | ||
|
||
// Assertions | ||
expect(exitCode).toBe(0); | ||
expect(stdout).toContain("You chose aqua, fuchsia, green"); | ||
}); | ||
|
||
it("returns an exit code of 0", async () => { | ||
const { exitCode, stderr, stdout } = await runTest( | ||
[cliExitCodePath], | ||
["sample text", ENTER] | ||
); | ||
|
||
// Assertions | ||
expect(exitCode).toBe(0); | ||
expect(stdout).toContain("sample text"); | ||
expect(stderr).toBeFalsy(); | ||
}); | ||
|
||
it("returns an exit code of 1", async () => { | ||
const { exitCode, stderr } = await runTest([cliExitCodePath], [ENTER]); | ||
|
||
// Assertions | ||
expect(exitCode).toBe(1); | ||
expect(stderr).toContain("Invalid input"); | ||
}); | ||
}); |