MCPcopy Create free account
hub / github.com/cortexkit/magic-context / MockPrompts

Class MockPrompts

packages/cli/src/commands/setup-pi.test.ts:27–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27class MockPrompts implements PromptIO {
28 readonly messages: string[] = [];
29 private readonly confirms: boolean[];
30 private readonly texts: string[];
31
32 constructor(options: { confirms: boolean[]; texts?: string[] }) {
33 this.confirms = [...options.confirms];
34 this.texts = [...(options.texts ?? [])];
35 }
36
37 readonly log = {
38 info: (message: string) => this.messages.push(`info:${message}`),
39 success: (message: string) => this.messages.push(`success:${message}`),
40 warn: (message: string) => this.messages.push(`warn:${message}`),
41 message: (message: string) => this.messages.push(`message:${message}`),
42 };
43
44 intro(message: string): void {
45 this.messages.push(`intro:${message}`);
46 }
47
48 outro(message: string): void {
49 this.messages.push(`outro:${message}`);
50 }
51
52 note(message: string, title?: string): void {
53 this.messages.push(`note:${title ?? ""}:${message}`);
54 }
55
56 spinner(): PromptSpinner {
57 return {
58 start: (message: string) => this.messages.push(`spinner-start:${message}`),
59 stop: (message: string) => this.messages.push(`spinner-stop:${message}`),
60 };
61 }
62
63 async confirm(): Promise<boolean> {
64 const next = this.confirms.shift();
65 if (next === undefined) throw new Error("No mock confirm response queued");
66 return next;
67 }
68
69 async text(_message: string, options = {}): Promise<string> {
70 return this.texts.shift() ?? options.initialValue ?? "";
71 }
72
73 async selectOne(_message: string, options: SelectOption[]): Promise<string> {
74 const recommended = options.find((option) => option.recommended);
75 return (recommended ?? options[0]).value;
76 }
77
78 async selectAutocomplete(_message: string, options: SelectOption[]): Promise<string> {
79 const recommended = options.find((option) => option.recommended);
80 return (recommended ?? options[0]).value;
81 }
82}
83
84afterEach(() => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected