[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

test: add tests for labels/hints in select (#273)

authored by

James Garbutt and committed by
GitHub
(Apr 6, 2025, 4:30 PM +0100) 7a6b8179 e6fc1b67

+243
+180
packages/prompts/src/__snapshots__/index.test.ts.snap
··· 169 169 ] 170 170 `; 171 171 172 + exports[`prompts (isCI = false) > multiselect > can render option hints 1`] = ` 173 + [ 174 + "[?25l", 175 + "│ 176 + ◆ foo 177 + │ ◻ opt0 (Hint 0) 178 + │ ◻ opt1 179 + └ 180 + ", 181 + "", 182 + "", 183 + "", 184 + "│ ◼ opt0 (Hint 0)", 185 + "", 186 + "", 187 + "", 188 + "", 189 + "◇ foo 190 + │ opt0", 191 + " 192 + ", 193 + "[?25h", 194 + ] 195 + `; 196 + 172 197 exports[`prompts (isCI = false) > multiselect > can set cursorAt to preselect an option 1`] = ` 173 198 [ 174 199 "[?25l", ··· 188 213 "", 189 214 "◇ foo 190 215 │ opt1", 216 + " 217 + ", 218 + "[?25h", 219 + ] 220 + `; 221 + 222 + exports[`prompts (isCI = false) > multiselect > can set custom labels 1`] = ` 223 + [ 224 + "[?25l", 225 + "│ 226 + ◆ foo 227 + │ ◻ Option 0 228 + │ ◻ Option 1 229 + └ 230 + ", 231 + "", 232 + "", 233 + "", 234 + "│ ◼ Option 0", 235 + "", 236 + "", 237 + "", 238 + "", 239 + "◇ foo 240 + │ Option 0", 191 241 " 192 242 ", 193 243 "[?25h", ··· 343 393 "", 344 394 "◇ foo 345 395 │ opt0", 396 + " 397 + ", 398 + "[?25h", 399 + ] 400 + `; 401 + 402 + exports[`prompts (isCI = false) > multiselect > renders multiple cancelled values 1`] = ` 403 + [ 404 + "[?25l", 405 + "│ 406 + ◆ foo 407 + │ ◻ opt0 408 + │ ◻ opt1 409 + │ ◻ opt2 410 + └ 411 + ", 412 + "", 413 + "", 414 + "", 415 + "│ ◼ opt0", 416 + "", 417 + "", 418 + "", 419 + "", 420 + "│ ◼ opt0 421 + │ ◻ opt1 422 + │ ◻ opt2 423 + └ 424 + ", 425 + "", 426 + "", 427 + "", 428 + "│ ◼ opt1", 429 + "", 430 + "", 431 + "", 432 + "", 433 + "■ foo 434 + │ opt0, opt1 435 + │", 346 436 " 347 437 ", 348 438 "[?25h", ··· 1244 1334 ] 1245 1335 `; 1246 1336 1337 + exports[`prompts (isCI = true) > multiselect > can render option hints 1`] = ` 1338 + [ 1339 + "[?25l", 1340 + "│ 1341 + ◆ foo 1342 + │ ◻ opt0 (Hint 0) 1343 + │ ◻ opt1 1344 + └ 1345 + ", 1346 + "", 1347 + "", 1348 + "", 1349 + "│ ◼ opt0 (Hint 0)", 1350 + "", 1351 + "", 1352 + "", 1353 + "", 1354 + "◇ foo 1355 + │ opt0", 1356 + " 1357 + ", 1358 + "[?25h", 1359 + ] 1360 + `; 1361 + 1247 1362 exports[`prompts (isCI = true) > multiselect > can set cursorAt to preselect an option 1`] = ` 1248 1363 [ 1249 1364 "[?25l", ··· 1263 1378 "", 1264 1379 "◇ foo 1265 1380 │ opt1", 1381 + " 1382 + ", 1383 + "[?25h", 1384 + ] 1385 + `; 1386 + 1387 + exports[`prompts (isCI = true) > multiselect > can set custom labels 1`] = ` 1388 + [ 1389 + "[?25l", 1390 + "│ 1391 + ◆ foo 1392 + │ ◻ Option 0 1393 + │ ◻ Option 1 1394 + └ 1395 + ", 1396 + "", 1397 + "", 1398 + "", 1399 + "│ ◼ Option 0", 1400 + "", 1401 + "", 1402 + "", 1403 + "", 1404 + "◇ foo 1405 + │ Option 0", 1266 1406 " 1267 1407 ", 1268 1408 "[?25h", ··· 1418 1558 "", 1419 1559 "◇ foo 1420 1560 │ opt0", 1561 + " 1562 + ", 1563 + "[?25h", 1564 + ] 1565 + `; 1566 + 1567 + exports[`prompts (isCI = true) > multiselect > renders multiple cancelled values 1`] = ` 1568 + [ 1569 + "[?25l", 1570 + "│ 1571 + ◆ foo 1572 + │ ◻ opt0 1573 + │ ◻ opt1 1574 + │ ◻ opt2 1575 + └ 1576 + ", 1577 + "", 1578 + "", 1579 + "", 1580 + "│ ◼ opt0", 1581 + "", 1582 + "", 1583 + "", 1584 + "", 1585 + "│ ◼ opt0 1586 + │ ◻ opt1 1587 + │ ◻ opt2 1588 + └ 1589 + ", 1590 + "", 1591 + "", 1592 + "", 1593 + "│ ◼ opt1", 1594 + "", 1595 + "", 1596 + "", 1597 + "", 1598 + "■ foo 1599 + │ opt0, opt1 1600 + │", 1421 1601 " 1422 1602 ", 1423 1603 "[?25h",
+63
packages/prompts/src/index.test.ts
··· 749 749 expect(value).toEqual(['opt0']); 750 750 expect(output.buffer).toMatchSnapshot(); 751 751 }); 752 + 753 + test('can set custom labels', async () => { 754 + const result = prompts.multiselect({ 755 + message: 'foo', 756 + options: [ 757 + { value: 'opt0', label: 'Option 0' }, 758 + { value: 'opt1', label: 'Option 1' }, 759 + ], 760 + input, 761 + output, 762 + }); 763 + 764 + input.emit('keypress', '', { name: 'space' }); 765 + input.emit('keypress', '', { name: 'return' }); 766 + 767 + const value = await result; 768 + 769 + expect(value).toEqual(['opt0']); 770 + expect(output.buffer).toMatchSnapshot(); 771 + }); 772 + 773 + test('can render option hints', async () => { 774 + const result = prompts.multiselect({ 775 + message: 'foo', 776 + options: [ 777 + { value: 'opt0', hint: 'Hint 0' }, 778 + { value: 'opt1', hint: 'Hint 1' }, 779 + ], 780 + input, 781 + output, 782 + }); 783 + 784 + input.emit('keypress', '', { name: 'space' }); 785 + input.emit('keypress', '', { name: 'return' }); 786 + 787 + const value = await result; 788 + 789 + expect(value).toEqual(['opt0']); 790 + expect(output.buffer).toMatchSnapshot(); 791 + }); 792 + 793 + test('renders multiple cancelled values', async () => { 794 + const result = prompts.multiselect({ 795 + message: 'foo', 796 + options: [ 797 + { value: 'opt0' }, 798 + { value: 'opt1' }, 799 + { value: 'opt2' } 800 + ], 801 + input, 802 + output, 803 + }); 804 + 805 + input.emit('keypress', '', { name: 'space' }); 806 + input.emit('keypress', '', { name: 'down' }); 807 + input.emit('keypress', '', { name: 'space' }); 808 + input.emit('keypress', '', { name: 'escape' }); 809 + 810 + const value = await result; 811 + 812 + expect(prompts.isCancel(value)).toBe(true); 813 + expect(output.buffer).toMatchSnapshot(); 814 + }); 752 815 }); 753 816 });