@@ -71,6 +71,14 @@ const mockLibConsoleCLI = {
7171 removeSelectedExtensionPoints : jest . fn ( )
7272}
7373
74+ const getCommandConfig = ( ) => {
75+ return {
76+ findCommand : jest . fn ( ) . mockReturnValue ( { } ) ,
77+ runCommand : jest . fn ( ) ,
78+ runHook : jest . fn ( )
79+ }
80+ }
81+
7482beforeEach ( ( ) => {
7583 mockRuntimeLib . undeployActions . mockReset ( )
7684 helpers . runInProcess . mockReset ( )
@@ -153,7 +161,6 @@ describe('run', () => {
153161 command . appConfig = cloneDeep ( mockConfigData )
154162 command . appConfig . actions = { dist : 'actions' }
155163 command . appConfig . web . distProd = 'dist'
156- command . config = { runCommand : jest . fn ( ) , runHook : jest . fn ( ) }
157164 command . buildOneExt = jest . fn ( )
158165 command . getFullConfig = jest . fn ( ) . mockResolvedValue ( {
159166 aio : {
@@ -173,6 +180,7 @@ describe('run', () => {
173180 } )
174181 command . getLibConsoleCLI = jest . fn ( ( ) => mockLibConsoleCLI )
175182 command . getAppExtConfigs = jest . fn ( )
183+ command . config = getCommandConfig ( )
176184 } )
177185
178186 afterEach ( ( ) => {
@@ -467,47 +475,41 @@ describe('run', () => {
467475 } )
468476
469477 test ( 'does NOT fire `event` hooks when feature flag is NOT enabled' , async ( ) => {
470- const runHook = jest . fn ( )
471- command . config = { runHook }
472478 command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
473479 command . argv = [ ]
474480 await command . run ( )
475481 expect ( command . error ) . not . toHaveBeenCalled ( )
476- expect ( runHook ) . not . toHaveBeenCalledWith ( 'pre-undeploy-event-reg' )
482+ expect ( command . config . runHook ) . not . toHaveBeenCalledWith ( 'pre-undeploy-event-reg' )
477483 } )
478484
479485 test ( 'does NOT fire `event` hooks when events flag is false' , async ( ) => {
480- const runHook = jest . fn ( )
481- command . config = { runHook }
482486 command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
483487 await command . run ( )
484488 expect ( command . error ) . not . toHaveBeenCalled ( )
485- expect ( runHook ) . not . toHaveBeenCalledWith ( 'pre-undeploy-event-reg' )
489+ expect ( command . config . runHook ) . not . toHaveBeenCalledWith ( 'pre-undeploy-event-reg' )
486490 } )
487491
488492 test ( 'DOES fire `event` hooks when feature flag IS enabled' , async ( ) => {
489- const runHook = jest . fn ( )
493+ command . config . runHook
490494 . mockResolvedValue ( {
491495 successes : [ 'ok' ] ,
492496 failures : [ ]
493497 } )
494- command . config = { runHook }
495498 command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
496499 await command . run ( )
497500 expect ( command . error ) . not . toHaveBeenCalled ( )
498- expect ( runHook ) . toHaveBeenCalledWith ( 'pre-undeploy-event-reg' , expect . any ( Object ) )
501+ expect ( command . config . runHook ) . toHaveBeenCalledWith ( 'pre-undeploy-event-reg' , expect . any ( Object ) )
499502 } )
500503
501504 test ( 'outputs error if events hook throws' , async ( ) => {
502- const runHook = jest . fn ( )
505+ command . config . runHook
503506 . mockResolvedValue ( {
504507 successes : [ ] ,
505508 failures : [ { plugin : { name : 'ifailedu' } , error : 'some error' } ]
506509 } )
507- command . config = { runHook }
508510 command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
509511 await command . run ( )
510- expect ( runHook ) . toHaveBeenCalledWith ( 'pre-undeploy-event-reg' , expect . any ( Object ) )
512+ expect ( command . config . runHook ) . toHaveBeenCalledWith ( 'pre-undeploy-event-reg' , expect . any ( Object ) )
511513 expect ( command . error ) . toHaveBeenCalledTimes ( 1 )
512514 } )
513515
@@ -756,4 +758,15 @@ describe('run', () => {
756758 expect ( mockWebLib . undeployWeb ) . toHaveBeenCalledTimes ( 1 )
757759 expect ( auditLogger . sendAppAssetsUndeployedAuditLog ) . toHaveBeenCalledTimes ( 1 )
758760 } )
761+
762+ test ( 'does not run app:clean command if not found' , async ( ) => {
763+ command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( ) )
764+ // Simulate findCommand returning undefined
765+ command . config . findCommand = jest . fn ( ) . mockReturnValue ( undefined )
766+ command . argv = [ ]
767+ await command . run ( )
768+ // Should not log or run app:clean
769+ expect ( command . log ) . not . toHaveBeenCalledWith ( 'running app:clean command' )
770+ expect ( command . config . runCommand ) . not . toHaveBeenCalledWith ( 'app:clean' )
771+ } )
759772} )
0 commit comments