|
1 | 1 | "use strict"; |
2 | 2 |
|
| 3 | +const path = require("path"); |
| 4 | + |
3 | 5 | const runTest = require("../"); |
4 | 6 |
|
5 | 7 | const DOWN = "\x1B\x5B\x42"; |
6 | 8 | const ENTER = "\x0D"; |
7 | 9 | const SPACE = "\x20"; |
8 | 10 |
|
9 | | -const cliPath = `${__dirname}/fixtures/cli.js`; |
| 11 | +const fixturesPath = path.join(__dirname, "fixtures"); |
| 12 | +const cliPath = path.join(fixturesPath, "cli.js"); |
| 13 | +const cliExitCodePath = path.join(fixturesPath, "cli-exit-code.js"); |
10 | 14 |
|
11 | 15 | describe("cli-prompts-test", () => { |
12 | 16 | it("picks a single option", async () => { |
13 | | - const { stdout } = await runTest( |
| 17 | + const { exitCode, stdout } = await runTest( |
14 | 18 | [cliPath], |
15 | 19 | [`${DOWN}${DOWN}${SPACE}${ENTER}`] |
16 | 20 | ); |
| 21 | + |
| 22 | + // Assertions |
| 23 | + expect(exitCode).toBe(0); |
17 | 24 | expect(stdout).toContain("You chose blue"); |
18 | 25 | }); |
19 | 26 |
|
20 | 27 | it("picks multiple options", async () => { |
21 | | - const { stdout } = await runTest( |
| 28 | + const { exitCode, stdout } = await runTest( |
22 | 29 | [cliPath], |
23 | 30 | [`${SPACE}${DOWN}${DOWN}${DOWN}${SPACE}${ENTER}${DOWN}${SPACE}${ENTER}`] |
24 | 31 | ); |
| 32 | + |
| 33 | + // Assertions |
| 34 | + expect(exitCode).toBe(0); |
25 | 35 | expect(stdout).toContain("You chose aqua, fuchsia, green"); |
26 | 36 | }); |
| 37 | + |
| 38 | + it("returns an exit code of 0", async () => { |
| 39 | + const { exitCode, stderr, stdout } = await runTest( |
| 40 | + [cliExitCodePath], |
| 41 | + ["sample text", ENTER] |
| 42 | + ); |
| 43 | + |
| 44 | + // Assertions |
| 45 | + expect(exitCode).toBe(0); |
| 46 | + expect(stdout).toContain("sample text"); |
| 47 | + expect(stderr).toBeFalsy(); |
| 48 | + }); |
| 49 | + |
| 50 | + it("returns an exit code of 1", async () => { |
| 51 | + const { exitCode, stderr } = await runTest([cliExitCodePath], [ENTER]); |
| 52 | + |
| 53 | + // Assertions |
| 54 | + expect(exitCode).toBe(1); |
| 55 | + expect(stderr).toContain("Invalid input"); |
| 56 | + }); |
27 | 57 | }); |
0 commit comments