|
1 | 1 | // Covers TUI launch argument and environment construction. |
2 | 2 | import type { ChildProcess, SpawnOptions } from "node:child_process"; |
3 | 3 | import { EventEmitter } from "node:events"; |
4 | | -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | +import { afterEach, beforeEach, describe, expect, it, type MockInstance, vi } from "vitest"; |
5 | 5 | |
6 | 6 | const spawnMock = vi.hoisted(() => vi.fn()); |
7 | 7 | const detachMock = vi.hoisted(() => vi.fn()); |
| 8 | +let pauseSpy: MockInstance; |
| 9 | +let resumeSpy: MockInstance; |
8 | 10 | |
9 | 11 | vi.mock("node:child_process", () => ({ |
10 | 12 | spawn: spawnMock, |
@@ -42,8 +44,8 @@ describe("launchTuiCli", () => {
|
42 | 44 | process.execArgv.length = 0; |
43 | 45 | spawnMock.mockReset(); |
44 | 46 | detachMock.mockReset(); |
45 | | -vi.spyOn(process.stdin, "pause").mockImplementation(() => process.stdin); |
46 | | -vi.spyOn(process.stdin, "resume").mockImplementation(() => process.stdin); |
| 47 | +pauseSpy = vi.spyOn(process.stdin, "pause").mockImplementation(() => process.stdin); |
| 48 | +resumeSpy = vi.spyOn(process.stdin, "resume").mockImplementation(() => process.stdin); |
47 | 49 | vi.spyOn(process.stdin, "isPaused").mockReturnValue(false); |
48 | 50 | }); |
49 | 51 | |
@@ -135,6 +137,19 @@ describe("launchTuiCli", () => {
|
135 | 137 | expect(options.stdio).toBe("inherit"); |
136 | 138 | }); |
137 | 139 | |
| 140 | +it("keeps parent stdin paused after the relaunched TUI exits", async () => { |
| 141 | +const child = createChildProcess(); |
| 142 | +spawnMock.mockImplementation((_cmd: string, _args: string[], _opts: SpawnOptions) => { |
| 143 | +queueMicrotask(() => child.emit("exit", 0, null)); |
| 144 | +return child; |
| 145 | +}); |
| 146 | + |
| 147 | +await launchTuiCli({ deliver: false }); |
| 148 | + |
| 149 | +expect(pauseSpy).toHaveBeenCalledOnce(); |
| 150 | +expect(resumeSpy).not.toHaveBeenCalled(); |
| 151 | +}); |
| 152 | + |
138 | 153 | it("launches compiled CLI shapes without repeating the current command", async () => { |
139 | 154 | process.argv[1] = "setup"; |
140 | 155 | const child = createChildProcess(); |
|