@@ -304,6 +304,138 @@ describe('FileUpload Adapter', () => {
304304 ) ;
305305 expect ( serverCommandCalls . length ) . toBe ( 0 ) ;
306306 } ) ;
307+
308+ it ( 'should prompt for streaming response when framework supports server commands and flag is not provided' ,
309+ async ( ) => {
310+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'test-project' ) ;
311+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'Default' ) ;
312+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'npm run build' ) ;
313+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( './dist' ) ;
314+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'npm start' ) ; // server command prompt
315+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( true ) ;
316+
317+ const createSignedUploadUrlMock = jest
318+ . spyOn ( FileUpload . prototype as any , 'createSignedUploadUrl' )
319+ . mockResolvedValue ( { uploadUid : 'test-upload-uid' } ) ;
320+ const archiveMock = jest
321+ . spyOn ( FileUpload . prototype as any , 'archive' )
322+ . mockResolvedValue ( { zipName : 'test.zip' , zipPath : '/path/to/test.zip' , projectName : 'test-project' } ) ;
323+ const uploadFileMock = jest
324+ . spyOn ( FileUpload . prototype as any , 'uploadFile' )
325+ . mockResolvedValue ( undefined ) ;
326+
327+ const fileUploadInstance = new FileUpload ( {
328+ config : {
329+ flags : {
330+ 'server-command' : undefined , // Make it undefined so it prompts for server command
331+ 'enable-streaming-response' : undefined ,
332+ } ,
333+ framework : 'OTHER' ,
334+ supportedFrameworksForServerCommands : [ 'ANGULAR' , 'OTHER' , 'REMIX' , 'NUXT' ] ,
335+ outputDirectories : { OTHER : './dist' } ,
336+ } ,
337+ log : logMock ,
338+ exit : exitMock ,
339+ } as any ) ;
340+
341+ await fileUploadInstance . prepareAndUploadNewProjectFile ( ) ;
342+
343+ expect ( cliux . inquire ) . toHaveBeenCalledWith ( {
344+ type : 'confirm' ,
345+ name : 'isStreamingEnabled' ,
346+ message : 'Enable Streaming Responses' ,
347+ default : false ,
348+ } ) ;
349+ expect ( fileUploadInstance . config . isStreamingEnabled ) . toBe ( true ) ;
350+
351+ createSignedUploadUrlMock . mockRestore ( ) ;
352+ archiveMock . mockRestore ( ) ;
353+ uploadFileMock . mockRestore ( ) ;
354+ } ) ;
355+
356+ it ( 'should not prompt for streaming response when flag is provided' , async ( ) => {
357+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'test-project' ) ;
358+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'Default' ) ;
359+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'npm run build' ) ;
360+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( './dist' ) ;
361+
362+ const createSignedUploadUrlMock = jest
363+ . spyOn ( FileUpload . prototype as any , 'createSignedUploadUrl' )
364+ . mockResolvedValue ( { uploadUid : 'test-upload-uid' } ) ;
365+ const archiveMock = jest
366+ . spyOn ( FileUpload . prototype as any , 'archive' )
367+ . mockResolvedValue ( { zipName : 'test.zip' , zipPath : '/path/to/test.zip' , projectName : 'test-project' } ) ;
368+ const uploadFileMock = jest
369+ . spyOn ( FileUpload . prototype as any , 'uploadFile' )
370+ . mockResolvedValue ( undefined ) ;
371+
372+ const fileUploadInstance = new FileUpload ( {
373+ config : {
374+ flags : {
375+ 'server-command' : 'npm start' ,
376+ 'enable-streaming-response' : true ,
377+ } ,
378+ framework : 'OTHER' ,
379+ supportedFrameworksForServerCommands : [ 'ANGULAR' , 'OTHER' , 'REMIX' , 'NUXT' ] ,
380+ outputDirectories : { OTHER : './dist' } ,
381+ } ,
382+ log : logMock ,
383+ exit : exitMock ,
384+ } as any ) ;
385+
386+ await fileUploadInstance . prepareAndUploadNewProjectFile ( ) ;
387+
388+ const streamingResponseCalls = ( cliux . inquire as jest . Mock ) . mock . calls . filter (
389+ ( call ) => call [ 0 ] ?. name === 'isStreamingEnabled' ,
390+ ) ;
391+ expect ( streamingResponseCalls . length ) . toBe ( 0 ) ;
392+ expect ( fileUploadInstance . config . isStreamingEnabled ) . toBe ( true ) ;
393+
394+ createSignedUploadUrlMock . mockRestore ( ) ;
395+ archiveMock . mockRestore ( ) ;
396+ uploadFileMock . mockRestore ( ) ;
397+ } ) ;
398+
399+ it ( 'should not prompt for streaming response when framework does not support server commands' , async ( ) => {
400+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'test-project' ) ;
401+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'Default' ) ;
402+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( 'npm run build' ) ;
403+ ( cliux . inquire as jest . Mock ) . mockResolvedValueOnce ( './public' ) ;
404+
405+ const createSignedUploadUrlMock = jest
406+ . spyOn ( FileUpload . prototype as any , 'createSignedUploadUrl' )
407+ . mockResolvedValue ( { uploadUid : 'test-upload-uid' } ) ;
408+ const archiveMock = jest
409+ . spyOn ( FileUpload . prototype as any , 'archive' )
410+ . mockResolvedValue ( { zipName : 'test.zip' , zipPath : '/path/to/test.zip' , projectName : 'test-project' } ) ;
411+ const uploadFileMock = jest
412+ . spyOn ( FileUpload . prototype as any , 'uploadFile' )
413+ . mockResolvedValue ( undefined ) ;
414+
415+ const fileUploadInstance = new FileUpload ( {
416+ config : {
417+ flags : {
418+ 'enable-streaming-response' : undefined ,
419+ } ,
420+ framework : 'GATSBY' ,
421+ supportedFrameworksForServerCommands : [ 'ANGULAR' , 'OTHER' , 'REMIX' , 'NUXT' ] ,
422+ outputDirectories : { GATSBY : './public' } ,
423+ } ,
424+ log : logMock ,
425+ exit : exitMock ,
426+ } as any ) ;
427+
428+ await fileUploadInstance . prepareAndUploadNewProjectFile ( ) ;
429+
430+ const streamingResponseCalls = ( cliux . inquire as jest . Mock ) . mock . calls . filter (
431+ ( call ) => call [ 0 ] ?. name === 'isStreamingEnabled' ,
432+ ) ;
433+ expect ( streamingResponseCalls . length ) . toBe ( 0 ) ;
434+
435+ createSignedUploadUrlMock . mockRestore ( ) ;
436+ archiveMock . mockRestore ( ) ;
437+ uploadFileMock . mockRestore ( ) ;
438+ } ) ;
307439 } ) ;
308440} ) ;
309441
0 commit comments