@@ -148,4 +148,107 @@ describe("CLI Main Function", () => {
148148 expect ( ( ) => mainCli ( ) ) . toThrow ( "Process exit called with code: 1" ) ;
149149 expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( "Usage: dotenv-mono" ) ) ;
150150 } ) ;
151+
152+ it ( "should handle --quiet flag" , ( ) => {
153+ process . argv = [ "node" , "cli.js" , "--quiet" , "--debug" ] ;
154+
155+ expect ( ( ) => mainCli ( ) ) . toThrow ( "Process exit called with code: 0" ) ;
156+ expect ( consoleLogSpy ) . toHaveBeenCalledWith (
157+ "Configuration:" ,
158+ expect . objectContaining ( { quiet : true } ) ,
159+ ) ;
160+ } ) ;
161+
162+ it ( "should handle --quiet flag with command execution" , ( ) => {
163+ mockFs ( {
164+ "/test" : {
165+ ".env" : "CLI_QUIET_TEST=quiet_value" ,
166+ } ,
167+ } ) ;
168+
169+ process . argv = [ "node" , "cli.js" , "--quiet" , "--cwd" , "/test" , "echo" , "test" ] ;
170+
171+ // Mock spawn to avoid actually executing commands in test environment
172+ const mockSpawn = jest . fn ( ) . mockReturnValue ( {
173+ on : jest . fn ( ) . mockImplementation ( ( event , callback ) => {
174+ if ( event === "exit" ) {
175+ setTimeout ( ( ) => callback ( 0 ) , 0 ) ; // Simulate successful command execution
176+ }
177+ return {
178+ kill : jest . fn ( ) ,
179+ } ;
180+ } ) ,
181+ kill : jest . fn ( ) ,
182+ } ) ;
183+
184+ // Mock cross-spawn
185+ jest . doMock ( "cross-spawn" , ( ) => mockSpawn ) ;
186+
187+ // The command should execute without throwing since we mock the child process
188+ expect ( ( ) => mainCli ( ) ) . not . toThrow ( ) ;
189+ } ) ;
190+
191+ it ( "should handle --quiet with -e flag" , ( ) => {
192+ process . argv = [ "node" , "cli.js" , "--quiet" , "-e" , "/test/.env" , "--debug" ] ;
193+
194+ expect ( ( ) => mainCli ( ) ) . toThrow ( "Process exit called with code: 0" ) ;
195+ expect ( consoleLogSpy ) . toHaveBeenCalledWith (
196+ "Configuration:" ,
197+ expect . objectContaining ( { quiet : true } ) ,
198+ ) ;
199+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( "Custom paths:" , [ "/test/.env" ] ) ;
200+ } ) ;
201+
202+ it ( "should handle --quiet with multiple flags" , ( ) => {
203+ process . argv = [
204+ "node" ,
205+ "cli.js" ,
206+ "--quiet" ,
207+ "--override" ,
208+ "--no-expand" ,
209+ "--depth" ,
210+ "5" ,
211+ "--debug" ,
212+ ] ;
213+
214+ expect ( ( ) => mainCli ( ) ) . toThrow ( "Process exit called with code: 0" ) ;
215+ expect ( consoleLogSpy ) . toHaveBeenCalledWith (
216+ "Configuration:" ,
217+ expect . objectContaining ( {
218+ quiet : true ,
219+ override : true ,
220+ expand : false ,
221+ depth : 5 ,
222+ } ) ,
223+ ) ;
224+ } ) ;
225+
226+ it ( "should handle --quiet with -v variables" , ( ) => {
227+ process . argv = [ "node" , "cli.js" , "--quiet" , "-v" , "QUIET_VAR=quiet_test" , "--debug" ] ;
228+
229+ expect ( ( ) => mainCli ( ) ) . toThrow ( "Process exit called with code: 0" ) ;
230+ expect ( consoleLogSpy ) . toHaveBeenCalledWith (
231+ "Configuration:" ,
232+ expect . objectContaining ( { quiet : true } ) ,
233+ ) ;
234+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( "Variables:" , [ [ "QUIET_VAR" , "quiet_test" ] ] ) ;
235+ } ) ;
236+
237+ it ( "should handle --quiet with -p print variable" , ( ) => {
238+ process . env . QUIET_PRINT_TEST = "quiet_print_value" ;
239+ process . argv = [ "node" , "cli.js" , "--quiet" , "-p" , "QUIET_PRINT_TEST" ] ;
240+
241+ expect ( ( ) => mainCli ( ) ) . toThrow ( "Process exit called with code: 0" ) ;
242+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( "quiet_print_value" ) ;
243+ } ) ;
244+
245+ it ( "should include --quiet in help output" , ( ) => {
246+ process . argv = [ "node" , "cli.js" , "--help" ] ;
247+
248+ expect ( ( ) => mainCli ( ) ) . toThrow ( "Process exit called with code: 0" ) ;
249+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( "--quiet" ) ) ;
250+ expect ( consoleLogSpy ) . toHaveBeenCalledWith (
251+ expect . stringContaining ( "suppress console output from dotenv" ) ,
252+ ) ;
253+ } ) ;
151254} ) ;
0 commit comments