@@ -50,6 +50,167 @@ describe("prompt", () => {
5050 } ) ;
5151 expect ( result ) . to . be . true ;
5252 } ) ;
53+
54+ it ( "handles non-interactive with default" , async ( ) => {
55+ const result = await prompt . confirm ( {
56+ message : "Continue?" ,
57+ nonInteractive : true ,
58+ default : false ,
59+ } ) ;
60+ expect ( result ) . to . be . false ;
61+ } ) ;
62+
63+ it ( "throws in non-interactive without default" , async ( ) => {
64+ await expect (
65+ prompt . confirm ( {
66+ message : "Continue?" ,
67+ nonInteractive : true ,
68+ } ) ,
69+ ) . to . be . rejectedWith (
70+ FirebaseError ,
71+ 'Question "Continue?" does not have a default and cannot be answered in non-interactive mode' ,
72+ ) ;
73+ } ) ;
74+ } ) ;
75+
76+ describe ( "input" , ( ) => {
77+ it ( "handles non-interactive with default" , async ( ) => {
78+ const result = await prompt . input ( {
79+ message : "Name?" ,
80+ nonInteractive : true ,
81+ default : "Inigo Montoya" ,
82+ } ) ;
83+ expect ( result ) . to . equal ( "Inigo Montoya" ) ;
84+ } ) ;
85+
86+ it ( "throws in non-interactive without default" , async ( ) => {
87+ await expect (
88+ prompt . input ( {
89+ message : "Name?" ,
90+ nonInteractive : true ,
91+ } ) ,
92+ ) . to . be . rejectedWith (
93+ FirebaseError ,
94+ 'Question "Name?" does not have a default and cannot be answered in non-interactive mode' ,
95+ ) ;
96+ } ) ;
97+ } ) ;
98+
99+ describe ( "checkbox" , ( ) => {
100+ it ( "handles non-interactive with default" , async ( ) => {
101+ const result = await prompt . checkbox ( {
102+ message : "Tools?" ,
103+ nonInteractive : true ,
104+ choices : [ "hammer" , "wrench" , "saw" ] ,
105+ default : [ "hammer" , "wrench" ] ,
106+ } ) ;
107+ expect ( result ) . to . deep . equal ( [ "hammer" , "wrench" ] ) ;
108+ } ) ;
109+
110+ it ( "throws in non-interactive without default" , async ( ) => {
111+ await expect (
112+ prompt . checkbox ( {
113+ message : "Tools?" ,
114+ nonInteractive : true ,
115+ choices : [ "hammer" , "wrench" , "saw" ] ,
116+ } ) ,
117+ ) . to . be . rejectedWith (
118+ FirebaseError ,
119+ 'Question "Tools?" does not have a default and cannot be answered in non-interactive mode' ,
120+ ) ;
121+ } ) ;
122+ } ) ;
123+
124+ describe ( "select" , ( ) => {
125+ it ( "handles non-interactive with default" , async ( ) => {
126+ const result = await prompt . select ( {
127+ message : "Tool?" ,
128+ nonInteractive : true ,
129+ choices : [ "hammer" , "wrench" , "saw" ] ,
130+ default : "wrench" ,
131+ } ) ;
132+ expect ( result ) . to . equal ( "wrench" ) ;
133+ } ) ;
134+
135+ it ( "throws in non-interactive without default" , async ( ) => {
136+ await expect (
137+ prompt . select ( {
138+ message : "Tool?" ,
139+ nonInteractive : true ,
140+ choices : [ "hammer" , "wrench" , "saw" ] ,
141+ } ) ,
142+ ) . to . be . rejectedWith (
143+ FirebaseError ,
144+ 'Question "Tool?" does not have a default and cannot be answered in non-interactive mode' ,
145+ ) ;
146+ } ) ;
147+ } ) ;
148+
149+ describe ( "number" , ( ) => {
150+ it ( "handles non-interactive with default" , async ( ) => {
151+ const result = await prompt . number ( {
152+ message : "Count?" ,
153+ nonInteractive : true ,
154+ default : 42 ,
155+ } ) ;
156+ expect ( result ) . to . equal ( 42 ) ;
157+ } ) ;
158+
159+ it ( "throws in non-interactive without default" , async ( ) => {
160+ await expect (
161+ prompt . number ( {
162+ message : "Count?" ,
163+ nonInteractive : true ,
164+ } ) ,
165+ ) . to . be . rejectedWith (
166+ FirebaseError ,
167+ 'Question "Count?" does not have a default and cannot be answered in non-interactive mode' ,
168+ ) ;
169+ } ) ;
170+ } ) ;
171+
172+ describe ( "password" , ( ) => {
173+ it ( "throws in non-interactive" , async ( ) => {
174+ await expect (
175+ prompt . password ( {
176+ message : "Password?" ,
177+ nonInteractive : true ,
178+ } ) ,
179+ ) . to . be . rejectedWith (
180+ FirebaseError ,
181+ 'Question "Password?" does not have a default and cannot be answered in non-interactive mode' ,
182+ ) ;
183+ } ) ;
184+ } ) ;
185+
186+ describe ( "search" , ( ) => {
187+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
188+ const source = ( term : string | undefined ) => {
189+ return [ "a" , "b" , "c" ] ;
190+ } ;
191+
192+ it ( "handles non-interactive with default" , async ( ) => {
193+ const result = await prompt . search ( {
194+ message : "Letter?" ,
195+ nonInteractive : true ,
196+ source,
197+ default : "b" ,
198+ } ) ;
199+ expect ( result ) . to . equal ( "b" ) ;
200+ } ) ;
201+
202+ it ( "throws in non-interactive without default" , async ( ) => {
203+ await expect (
204+ prompt . search ( {
205+ message : "Letter?" ,
206+ nonInteractive : true ,
207+ source,
208+ } ) ,
209+ ) . to . be . rejectedWith (
210+ FirebaseError ,
211+ 'Question "Letter?" does not have a default and cannot be answered in non-interactive mode' ,
212+ ) ;
213+ } ) ;
53214 } ) ;
54215 } ) ;
55216} ) ;
0 commit comments