Skip to content

Commit fdf6860

Browse files
committed
add test
1 parent 1e1fe68 commit fdf6860

File tree

2 files changed

+234
-0
lines changed

2 files changed

+234
-0
lines changed

packages/prompts/test/__snapshots__/spinner.test.ts.snap

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,209 @@ exports[`spinner (isCI = false) > indicator customization > custom delay 1`] = `
3434
]
3535
`;
3636
37+
exports[`spinner (isCI = false) > indicator customization > custom frame style 1`] = `
38+
[
39+
"<cursor.hide>",
40+
"│
41+
",
42+
"◒ ",
43+
"<cursor.left count=1>",
44+
"<erase.down>",
45+
"◐ ",
46+
"<cursor.left count=1>",
47+
"<erase.down>",
48+
"◓ ",
49+
"<cursor.left count=1>",
50+
"<erase.down>",
51+
"◑ ",
52+
"<cursor.left count=1>",
53+
"<erase.down>",
54+
"◒ ",
55+
"<cursor.left count=1>",
56+
"<erase.down>",
57+
"◐ ",
58+
"<cursor.left count=1>",
59+
"<erase.down>",
60+
"◓ ",
61+
"<cursor.left count=1>",
62+
"<erase.down>",
63+
"◑ ",
64+
"<cursor.left count=1>",
65+
"<erase.down>",
66+
"◒ .",
67+
"<cursor.left count=1>",
68+
"<erase.down>",
69+
"◐ .",
70+
"<cursor.left count=1>",
71+
"<erase.down>",
72+
"◓ .",
73+
"<cursor.left count=1>",
74+
"<erase.down>",
75+
"◑ .",
76+
"<cursor.left count=1>",
77+
"<erase.down>",
78+
"◒ .",
79+
"<cursor.left count=1>",
80+
"<erase.down>",
81+
"◐ .",
82+
"<cursor.left count=1>",
83+
"<erase.down>",
84+
"◓ .",
85+
"<cursor.left count=1>",
86+
"<erase.down>",
87+
"◑ .",
88+
"<cursor.left count=1>",
89+
"<erase.down>",
90+
"◒ ..",
91+
"<cursor.left count=1>",
92+
"<erase.down>",
93+
"◐ ..",
94+
"<cursor.left count=1>",
95+
"<erase.down>",
96+
"◓ ..",
97+
"<cursor.left count=1>",
98+
"<erase.down>",
99+
"◑ ..",
100+
"<cursor.left count=1>",
101+
"<erase.down>",
102+
"◒ ..",
103+
"<cursor.left count=1>",
104+
"<erase.down>",
105+
"◐ ..",
106+
"<cursor.left count=1>",
107+
"<erase.down>",
108+
"◓ ..",
109+
"<cursor.left count=1>",
110+
"<erase.down>",
111+
"◑ ..",
112+
"<cursor.left count=1>",
113+
"<erase.down>",
114+
"◒ ...",
115+
"<cursor.left count=1>",
116+
"<erase.down>",
117+
"◐ ...",
118+
"<cursor.left count=1>",
119+
"<erase.down>",
120+
"◓ ...",
121+
"<cursor.left count=1>",
122+
"<erase.down>",
123+
"◑ ...",
124+
"<cursor.left count=1>",
125+
"<erase.down>",
126+
"◒ ...",
127+
"<cursor.left count=1>",
128+
"<erase.down>",
129+
"◐ ...",
130+
"<cursor.left count=1>",
131+
"<erase.down>",
132+
"◓ ...",
133+
"<cursor.left count=1>",
134+
"<erase.down>",
135+
"◑ ...",
136+
"<cursor.left count=1>",
137+
"<erase.down>",
138+
"◒ ...",
139+
"<cursor.left count=1>",
140+
"<erase.down>",
141+
"◐ ",
142+
"<cursor.left count=1>",
143+
"<erase.down>",
144+
"◓ ",
145+
"<cursor.left count=1>",
146+
"<erase.down>",
147+
"◑ ",
148+
"<cursor.left count=1>",
149+
"<erase.down>",
150+
"◒ ",
151+
"<cursor.left count=1>",
152+
"<erase.down>",
153+
"◐ ",
154+
"<cursor.left count=1>",
155+
"<erase.down>",
156+
"◓ ",
157+
"<cursor.left count=1>",
158+
"<erase.down>",
159+
"◑ ",
160+
"<cursor.left count=1>",
161+
"<erase.down>",
162+
"◒ ",
163+
"<cursor.left count=1>",
164+
"<erase.down>",
165+
"◐ .",
166+
"<cursor.left count=1>",
167+
"<erase.down>",
168+
"◓ .",
169+
"<cursor.left count=1>",
170+
"<erase.down>",
171+
"◑ .",
172+
"<cursor.left count=1>",
173+
"<erase.down>",
174+
"◒ .",
175+
"<cursor.left count=1>",
176+
"<erase.down>",
177+
"◐ .",
178+
"<cursor.left count=1>",
179+
"<erase.down>",
180+
"◓ .",
181+
"<cursor.left count=1>",
182+
"<erase.down>",
183+
"◑ .",
184+
"<cursor.left count=1>",
185+
"<erase.down>",
186+
"◒ .",
187+
"<cursor.left count=1>",
188+
"<erase.down>",
189+
"◐ ..",
190+
"<cursor.left count=1>",
191+
"<erase.down>",
192+
"◓ ..",
193+
"<cursor.left count=1>",
194+
"<erase.down>",
195+
"◑ ..",
196+
"<cursor.left count=1>",
197+
"<erase.down>",
198+
"◒ ..",
199+
"<cursor.left count=1>",
200+
"<erase.down>",
201+
"◐ ..",
202+
"<cursor.left count=1>",
203+
"<erase.down>",
204+
"◓ ..",
205+
"<cursor.left count=1>",
206+
"<erase.down>",
207+
"◑ ..",
208+
"<cursor.left count=1>",
209+
"<erase.down>",
210+
"◒ ..",
211+
"<cursor.left count=1>",
212+
"<erase.down>",
213+
"◐ ...",
214+
"<cursor.left count=1>",
215+
"<erase.down>",
216+
"◓ ...",
217+
"<cursor.left count=1>",
218+
"<erase.down>",
219+
"◑ ...",
220+
"<cursor.left count=1>",
221+
"<erase.down>",
222+
"◒ ...",
223+
"<cursor.left count=1>",
224+
"<erase.down>",
225+
"◐ ...",
226+
"<cursor.left count=1>",
227+
"<erase.down>",
228+
"◓ ...",
229+
"<cursor.left count=1>",
230+
"<erase.down>",
231+
"◑ ...",
232+
"<cursor.left count=1>",
233+
"<erase.down>",
234+
"◇
235+
",
236+
"<cursor.show>",
237+
]
238+
`;
239+
37240
exports[`spinner (isCI = false) > indicator customization > custom frames 1`] = `
38241
[
39242
"<cursor.hide>",
@@ -535,6 +738,22 @@ exports[`spinner (isCI = true) > indicator customization > custom delay 1`] = `
535738
]
536739
`;
537740
741+
exports[`spinner (isCI = true) > indicator customization > custom frame style 1`] = `
742+
[
743+
"<cursor.hide>",
744+
"│
745+
",
746+
"◒ ...",
747+
"
748+
",
749+
"<cursor.left count=1>",
750+
"<erase.down>",
751+
"◇
752+
",
753+
"<cursor.show>",
754+
]
755+
`;
756+
538757
exports[`spinner (isCI = true) > indicator customization > custom frames 1`] = `
539758
[
540759
"<cursor.hide>",

packages/prompts/test/spinner.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getColumns } from '@clack/core';
33
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
44
import * as prompts from '../src/index.js';
55
import { MockWritable } from './test-utils.js';
6+
import color from 'picocolors';
67

78
describe.each(['true', 'false'])('spinner (isCI = %s)', (isCI) => {
89
let originalCI: string | undefined;
@@ -233,6 +234,20 @@ describe.each(['true', 'false'])('spinner (isCI = %s)', (isCI) => {
233234

234235
expect(output.buffer).toMatchSnapshot();
235236
});
237+
238+
test('custom frame style', () => {
239+
const result = prompts.spinner({ output, styleFrame: color.red });
240+
241+
result.start();
242+
243+
for (let i = 0; i < 64; i++) {
244+
vi.advanceTimersByTime(80);
245+
}
246+
247+
result.stop();
248+
249+
expect(output.buffer).toMatchSnapshot();
250+
});
236251
});
237252

238253
describe('process exit handling', () => {

0 commit comments

Comments
 (0)