| 23 | } |
| 24 | |
| 25 | class MockPrompts implements PromptIO { |
| 26 | readonly messages: string[] = []; |
| 27 | private readonly texts: string[]; |
| 28 | private readonly confirms: boolean[]; |
| 29 | |
| 30 | constructor(options: { texts?: string[]; confirms?: boolean[] } = {}) { |
| 31 | this.texts = [...(options.texts ?? [])]; |
| 32 | this.confirms = [...(options.confirms ?? [])]; |
| 33 | } |
| 34 | |
| 35 | readonly log = { |
| 36 | info: (message: string) => this.messages.push(`info:${message}`), |
| 37 | success: (message: string) => this.messages.push(`success:${message}`), |
| 38 | warn: (message: string) => this.messages.push(`warn:${message}`), |
| 39 | message: (message: string) => this.messages.push(`message:${message}`), |
| 40 | }; |
| 41 | |
| 42 | intro(message: string): void { |
| 43 | this.messages.push(`intro:${message}`); |
| 44 | } |
| 45 | |
| 46 | outro(message: string): void { |
| 47 | this.messages.push(`outro:${message}`); |
| 48 | } |
| 49 | |
| 50 | note(message: string, title?: string): void { |
| 51 | this.messages.push(`note:${title ?? ""}:${message}`); |
| 52 | } |
| 53 | |
| 54 | spinner(): PromptSpinner { |
| 55 | return { |
| 56 | start: (message: string) => this.messages.push(`spinner-start:${message}`), |
| 57 | stop: (message: string) => this.messages.push(`spinner-stop:${message}`), |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | async confirm(): Promise<boolean> { |
| 62 | return this.confirms.shift() ?? false; |
| 63 | } |
| 64 | |
| 65 | async text(_message: string, options = {}): Promise<string> { |
| 66 | return this.texts.shift() ?? options.initialValue ?? "mock text"; |
| 67 | } |
| 68 | |
| 69 | async selectOne(_message: string, options: SelectOption[]): Promise<string> { |
| 70 | return options.find((option) => option.recommended)?.value ?? options[0].value; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | function setEnv(root: string, cwd: string): string { |
| 75 | process.env.HOME = root; |
nothing calls this directly
no outgoing calls
no test coverage detected