Minimal scripted PromptIO: confirms/selects/texts are FIFO queues.
| 4 | |
| 5 | /** Minimal scripted PromptIO: confirms/selects/texts are FIFO queues. */ |
| 6 | class MockPrompts implements PromptIO { |
| 7 | private confirms: boolean[]; |
| 8 | private selects: string[]; |
| 9 | private texts: string[]; |
| 10 | private autos: string[]; |
| 11 | readonly notes: string[] = []; |
| 12 | log: PromptLog = { |
| 13 | info: () => {}, |
| 14 | success: () => {}, |
| 15 | warn: () => {}, |
| 16 | error: () => {}, |
| 17 | message: () => {}, |
| 18 | step: () => {}, |
| 19 | }; |
| 20 | |
| 21 | constructor(opts: { |
| 22 | confirms?: boolean[]; |
| 23 | selects?: string[]; |
| 24 | texts?: string[]; |
| 25 | autos?: string[]; |
| 26 | }) { |
| 27 | this.confirms = [...(opts.confirms ?? [])]; |
| 28 | this.selects = [...(opts.selects ?? [])]; |
| 29 | this.texts = [...(opts.texts ?? [])]; |
| 30 | this.autos = [...(opts.autos ?? [])]; |
| 31 | } |
| 32 | intro(): void {} |
| 33 | outro(): void {} |
| 34 | note(message: string, title?: string): void { |
| 35 | this.notes.push(`${title ?? ""}:${message}`); |
| 36 | } |
| 37 | spinner(): PromptSpinner { |
| 38 | return { start: () => {}, stop: () => {}, message: () => {} }; |
| 39 | } |
| 40 | async confirm(): Promise<boolean> { |
| 41 | const v = this.confirms.shift(); |
| 42 | if (v === undefined) throw new Error("no confirm queued"); |
| 43 | return v; |
| 44 | } |
| 45 | async text(): Promise<string> { |
| 46 | return this.texts.shift() ?? ""; |
| 47 | } |
| 48 | async selectOne(_message: string, options: SelectOption[]): Promise<string> { |
| 49 | const v = this.selects.shift(); |
| 50 | if (v !== undefined) return v; |
| 51 | const rec = options.find((o) => o.recommended); |
| 52 | return (rec ?? options[0]).value; |
| 53 | } |
| 54 | async selectMany(): Promise<string[]> { |
| 55 | return []; |
| 56 | } |
| 57 | async selectAutocomplete(_message: string, options: SelectOption[]): Promise<string> { |
| 58 | const v = this.autos.shift(); |
| 59 | if (v !== undefined) return v; |
| 60 | return options[0]?.value ?? ""; |
| 61 | } |
| 62 | } |
| 63 |
nothing calls this directly
no outgoing calls
no test coverage detected