11import { jest } from '@jest/globals'
22
3- import inquirer from 'inquirer'
3+ import type { select } from '@ inquirer/prompts '
44import log4js from 'log4js'
55
66import type {
@@ -25,13 +25,12 @@ import type {
2525import type { SimpleType } from '../../test-lib/simple-type.js'
2626
2727
28- const promptMock = jest . fn < typeof inquirer . prompt > ( )
29- jest . unstable_mockModule ( 'inquirer' , ( ) => ( {
30- default : {
31- prompt : promptMock ,
32- } ,
28+ const selectMock = jest . fn < typeof select > ( )
29+ jest . unstable_mockModule ( '@inquirer/prompts' , ( ) => ( {
30+ select : selectMock ,
3331} ) )
3432
33+
3534const resetManagedConfigKeyMock = jest . fn < typeof resetManagedConfigKey > ( )
3635const setConfigKeyMock = jest . fn < typeof setConfigKey > ( )
3736jest . unstable_mockModule ( '../../../lib/cli-config.js' , ( ) => ( {
@@ -235,7 +234,7 @@ describe('selectFromList', () => {
235234 expect ( stringGetIdFromUserMock ) . not . toHaveBeenCalled ( )
236235
237236 expect ( booleanConfigValueMock ) . not . toHaveBeenCalled ( )
238- expect ( promptMock ) . not . toHaveBeenCalled ( )
237+ expect ( selectMock ) . not . toHaveBeenCalled ( )
239238 expect ( setConfigKeyMock ) . not . toHaveBeenCalled ( )
240239 expect ( getItemMock ) . not . toHaveBeenCalled ( )
241240 expect ( userMessageMock ) . not . toHaveBeenCalled ( )
@@ -251,7 +250,7 @@ describe('selectFromList', () => {
251250 expect ( stringGetIdFromUserMock ) . toHaveBeenCalledTimes ( 1 )
252251
253252 expect ( booleanConfigValueMock ) . not . toHaveBeenCalled ( )
254- expect ( promptMock ) . not . toHaveBeenCalled ( )
253+ expect ( selectMock ) . not . toHaveBeenCalled ( )
255254 expect ( setConfigKeyMock ) . not . toHaveBeenCalled ( )
256255 expect ( getItemMock ) . not . toHaveBeenCalled ( )
257256 expect ( userMessageMock ) . not . toHaveBeenCalled ( )
@@ -275,7 +274,7 @@ describe('selectFromList', () => {
275274 expect ( stringGetIdFromUserMock ) . not . toHaveBeenCalled ( )
276275
277276 expect ( booleanConfigValueMock ) . not . toHaveBeenCalled ( )
278- expect ( promptMock ) . not . toHaveBeenCalled ( )
277+ expect ( selectMock ) . not . toHaveBeenCalled ( )
279278 expect ( setConfigKeyMock ) . not . toHaveBeenCalled ( )
280279 expect ( userMessageMock ) . toHaveBeenCalledExactlyOnceWith ( item1 )
281280 expect ( resetManagedConfigKeyMock ) . not . toHaveBeenCalled ( )
@@ -286,7 +285,7 @@ describe('selectFromList', () => {
286285 defaultItem : 'default-item-id' ,
287286 } )
288287 getItemMock . mockResolvedValueOnce ( undefined as unknown as SimpleType )
289- promptMock . mockResolvedValue ( { answer : 'No' } )
288+ selectMock . mockResolvedValue ( 'no' )
290289
291290 const options = { listItems : listItemsMock , defaultValue }
292291 expect ( await selectFromList ( commandWithDefault , config , options ) ) . toBe ( 'chosen-id' )
@@ -296,7 +295,7 @@ describe('selectFromList', () => {
296295 expect ( stringGetIdFromUserMock ) . toHaveBeenCalledTimes ( 1 )
297296
298297 expect ( booleanConfigValueMock ) . toHaveBeenCalledTimes ( 1 )
299- expect ( promptMock ) . toHaveBeenCalledTimes ( 1 )
298+ expect ( selectMock ) . toHaveBeenCalledTimes ( 1 )
300299 expect ( setConfigKeyMock ) . not . toHaveBeenCalled ( )
301300 expect ( getItemMock ) . toHaveBeenCalledExactlyOnceWith ( 'default-item-id' )
302301 expect ( userMessageMock ) . not . toHaveBeenCalled ( )
@@ -311,7 +310,7 @@ describe('selectFromList', () => {
311310 defaultItem : 'default-item-id' ,
312311 } )
313312 getItemMock . mockRejectedValueOnce ( { response : { status : statusCode } } )
314- promptMock . mockResolvedValue ( { answer : 'No' } )
313+ selectMock . mockResolvedValue ( 'no' )
315314
316315 const options = { listItems : listItemsMock , defaultValue }
317316 expect ( await selectFromList ( commandWithDefault , config , options ) ) . toBe ( 'chosen-id' )
@@ -321,7 +320,7 @@ describe('selectFromList', () => {
321320 expect ( stringGetIdFromUserMock ) . toHaveBeenCalledTimes ( 1 )
322321
323322 expect ( booleanConfigValueMock ) . toHaveBeenCalledTimes ( 1 )
324- expect ( promptMock ) . toHaveBeenCalledTimes ( 1 )
323+ expect ( selectMock ) . toHaveBeenCalledTimes ( 1 )
325324 expect ( setConfigKeyMock ) . not . toHaveBeenCalled ( )
326325 expect ( getItemMock ) . toHaveBeenCalledExactlyOnceWith ( 'default-item-id' )
327326 expect ( userMessageMock ) . not . toHaveBeenCalled ( )
@@ -335,7 +334,7 @@ describe('selectFromList', () => {
335334 defaultItem : 'default-item-id' ,
336335 } )
337336 getItemMock . mockRejectedValueOnce ( Error ( 'unexpected error' ) )
338- promptMock . mockResolvedValue ( { answer : 'No' } )
337+ selectMock . mockResolvedValue ( 'no' )
339338
340339 const options = { listItems : listItemsMock , defaultValue }
341340 await expect ( selectFromList ( commandWithDefault , config , options ) )
@@ -346,7 +345,7 @@ describe('selectFromList', () => {
346345 expect ( stringGetIdFromUserMock ) . not . toHaveBeenCalled ( )
347346
348347 expect ( booleanConfigValueMock ) . not . toHaveBeenCalled ( )
349- expect ( promptMock ) . not . toHaveBeenCalled ( )
348+ expect ( selectMock ) . not . toHaveBeenCalled ( )
350349 expect ( setConfigKeyMock ) . not . toHaveBeenCalled ( )
351350 expect ( getItemMock ) . toHaveBeenCalledExactlyOnceWith ( 'default-item-id' )
352351 expect ( userMessageMock ) . not . toHaveBeenCalled ( )
@@ -355,7 +354,7 @@ describe('selectFromList', () => {
355354
356355 it ( 'does not save default when user asked not to' , async ( ) => {
357356 booleanConfigValueMock . mockReturnValueOnce ( false )
358- promptMock . mockResolvedValue ( { answer : 'No' } )
357+ selectMock . mockResolvedValue ( 'no' )
359358
360359 expect ( await selectFromList ( command , config ,
361360 { listItems : listItemsMock , defaultValue } ) ) . toBe ( 'chosen-id' )
@@ -366,8 +365,8 @@ describe('selectFromList', () => {
366365
367366 expect ( booleanConfigValueMock )
368367 . toHaveBeenCalledExactlyOnceWith ( 'defaultItem::neverAskForSaveAgain' )
369- expect ( promptMock ) . toHaveBeenCalledExactlyOnceWith (
370- expect . objectContaining ( { type : 'list' , name : 'answer ' } ) ,
368+ expect ( selectMock ) . toHaveBeenCalledExactlyOnceWith (
369+ expect . objectContaining ( { message : 'Do you want to save this as the default? ' } ) ,
371370 )
372371 expect ( setConfigKeyMock ) . not . toHaveBeenCalled ( )
373372 } )
@@ -384,13 +383,13 @@ describe('selectFromList', () => {
384383
385384 expect ( booleanConfigValueMock )
386385 . toHaveBeenCalledExactlyOnceWith ( 'defaultItem::neverAskForSaveAgain' )
387- expect ( promptMock ) . not . toHaveBeenCalled ( )
386+ expect ( selectMock ) . not . toHaveBeenCalled ( )
388387 expect ( setConfigKeyMock ) . not . toHaveBeenCalled ( )
389388 } )
390389
391390 it ( 'saves selected item as default' , async ( ) => {
392391 booleanConfigValueMock . mockReturnValueOnce ( false )
393- promptMock . mockResolvedValue ( { answer : 'yes' } )
392+ selectMock . mockResolvedValue ( 'yes' )
394393
395394 expect ( await selectFromList ( command , config ,
396395 { listItems : listItemsMock , defaultValue } ) ) . toBe ( 'chosen-id' )
@@ -401,8 +400,8 @@ describe('selectFromList', () => {
401400
402401 expect ( booleanConfigValueMock )
403402 . toHaveBeenCalledExactlyOnceWith ( 'defaultItem::neverAskForSaveAgain' )
404- expect ( promptMock ) . toHaveBeenCalledExactlyOnceWith (
405- expect . objectContaining ( { type : 'list' , name : 'answer ' } ) ,
403+ expect ( selectMock ) . toHaveBeenCalledExactlyOnceWith (
404+ expect . objectContaining ( { message : 'Do you want to save this as the default? ' } ) ,
406405 )
407406 expect ( setConfigKeyMock )
408407 . toHaveBeenCalledExactlyOnceWith ( command . cliConfig , 'defaultItem' , 'chosen-id' )
@@ -412,7 +411,7 @@ describe('selectFromList', () => {
412411
413412 it ( 'saves "never ask again" response"' , async ( ) => {
414413 booleanConfigValueMock . mockReturnValueOnce ( false )
415- promptMock . mockResolvedValue ( { answer : 'never' } )
414+ selectMock . mockResolvedValue ( 'never' )
416415
417416 expect ( await selectFromList ( command , config ,
418417 { listItems : listItemsMock , defaultValue } ) ) . toBe ( 'chosen-id' )
@@ -423,8 +422,8 @@ describe('selectFromList', () => {
423422
424423 expect ( booleanConfigValueMock ) . toHaveBeenCalledTimes ( 1 )
425424 expect ( booleanConfigValueMock ) . toHaveBeenCalledWith ( 'defaultItem::neverAskForSaveAgain' )
426- expect ( promptMock ) . toHaveBeenCalledExactlyOnceWith (
427- expect . objectContaining ( { type : 'list' , name : 'answer ' } ) ,
425+ expect ( selectMock ) . toHaveBeenCalledExactlyOnceWith (
426+ expect . objectContaining ( { message : 'Do you want to save this as the default? ' } ) ,
428427 )
429428 expect ( setConfigKeyMock ) . toHaveBeenCalledExactlyOnceWith (
430429 command . cliConfig ,
0 commit comments