@@ -86,6 +86,9 @@ describe('Inquirerer', () => {
8686 }
8787 } ) ;
8888
89+ inputQueue = [ ] ;
90+ currentInputIndex = 0 ;
91+
8992 setupReadlineMock ( ) ;
9093 // Pipe the transform stream to the mock output to intercept writes
9194 // transformStream.pipe(mockOutput);
@@ -334,6 +337,139 @@ describe('Inquirerer', () => {
334337 } ) ;
335338 } ) ;
336339
340+ describe ( 'boolean type (alias for confirm)' , ( ) => {
341+ it ( 'should treat boolean type as confirm — yes input' , async ( ) => {
342+ enqueueInputResponse ( { type : 'read' , value : 'y' } ) ;
343+
344+ const prompter = new Inquirerer ( {
345+ input : mockInput ,
346+ output : mockOutput ,
347+ noTty : false
348+ } ) ;
349+ const questions : Question [ ] = [
350+ { name : 'isActive' , type : 'boolean' } ,
351+ ] ;
352+
353+ const result = await prompter . prompt ( { } , questions ) ;
354+
355+ expect ( result ) . toEqual ( { isActive : true } ) ;
356+ } ) ;
357+
358+ it ( 'should treat boolean type as confirm — no input' , async ( ) => {
359+ enqueueInputResponse ( { type : 'read' , value : 'n' } ) ;
360+
361+ const prompter = new Inquirerer ( {
362+ input : mockInput ,
363+ output : mockOutput ,
364+ noTty : false
365+ } ) ;
366+ const questions : Question [ ] = [
367+ { name : 'isActive' , type : 'boolean' } ,
368+ ] ;
369+
370+ const result = await prompter . prompt ( { } , questions ) ;
371+
372+ expect ( result ) . toEqual ( { isActive : false } ) ;
373+ } ) ;
374+
375+ it ( 'should use default for boolean type in noTty mode' , async ( ) => {
376+ const prompter = new Inquirerer ( {
377+ input : mockInput ,
378+ output : mockOutput ,
379+ noTty : true
380+ } ) ;
381+ const questions : Question [ ] = [
382+ { name : 'isActive' , type : 'boolean' , default : true } ,
383+ ] ;
384+
385+ const result = await prompter . prompt ( { } , questions ) ;
386+
387+ expect ( result ) . toEqual ( { isActive : true } ) ;
388+ } ) ;
389+
390+ it ( 'should accept CLI flag override for boolean type' , async ( ) => {
391+ const prompter = new Inquirerer ( {
392+ input : mockInput ,
393+ output : mockOutput ,
394+ noTty : false
395+ } ) ;
396+ const questions : Question [ ] = [
397+ { name : 'isActive' , type : 'boolean' } ,
398+ ] ;
399+
400+ const result = await prompter . prompt ( { isActive : true } , questions ) ;
401+
402+ expect ( result ) . toEqual ( { isActive : true } ) ;
403+ } ) ;
404+ } ) ;
405+
406+ describe ( 'json type' , ( ) => {
407+ it ( 'should parse valid JSON input' , async ( ) => {
408+ enqueueInputResponse ( { type : 'read' , value : '{"email":"test@example.com","password":"secret"}' } ) ;
409+
410+ const prompter = new Inquirerer ( {
411+ input : mockInput ,
412+ output : mockOutput ,
413+ noTty : false
414+ } ) ;
415+ const questions : Question [ ] = [
416+ { name : 'input' , type : 'json' } ,
417+ ] ;
418+
419+ const result = await prompter . prompt ( { } , questions ) ;
420+
421+ expect ( result ) . toEqual ( { input : { email : 'test@example.com' , password : 'secret' } } ) ;
422+ } ) ;
423+
424+ it ( 'should return null for invalid JSON input' , async ( ) => {
425+ enqueueInputResponse ( { type : 'read' , value : 'not valid json' } ) ;
426+
427+ const prompter = new Inquirerer ( {
428+ input : mockInput ,
429+ output : mockOutput ,
430+ noTty : false
431+ } ) ;
432+ const questions : Question [ ] = [
433+ { name : 'data' , type : 'json' } ,
434+ ] ;
435+
436+ const result = await prompter . prompt ( { } , questions ) ;
437+
438+ // Invalid JSON returns null from the handler
439+ expect ( result ) . toEqual ( { data : null } ) ;
440+ } ) ;
441+
442+ it ( 'should use default for json type in noTty mode' , async ( ) => {
443+ const prompter = new Inquirerer ( {
444+ input : mockInput ,
445+ output : mockOutput ,
446+ noTty : true
447+ } ) ;
448+ const questions : Question [ ] = [
449+ { name : 'config' , type : 'json' , default : { key : 'value' } } ,
450+ ] ;
451+
452+ const result = await prompter . prompt ( { } , questions ) ;
453+
454+ expect ( result ) . toEqual ( { config : { key : 'value' } } ) ;
455+ } ) ;
456+
457+ it ( 'should accept CLI flag override for json type' , async ( ) => {
458+ const prompter = new Inquirerer ( {
459+ input : mockInput ,
460+ output : mockOutput ,
461+ noTty : false
462+ } ) ;
463+ const questions : Question [ ] = [
464+ { name : 'data' , type : 'json' } ,
465+ ] ;
466+
467+ const result = await prompter . prompt ( { data : { foo : 'bar' } } , questions ) ;
468+
469+ expect ( result ) . toEqual ( { data : { foo : 'bar' } } ) ;
470+ } ) ;
471+ } ) ;
472+
337473 it ( 'handles readline inputs' , async ( ) => {
338474
339475 const prompter = new Inquirerer ( {
0 commit comments