@@ -682,4 +682,169 @@ end`
682
682
} ) ;
683
683
} ) ;
684
684
} ) ;
685
+
686
+ describe ( "executePodInstall" , ( ) => {
687
+ const projectRoot = "nativeProjectRoot" ;
688
+ const xcodeProjPath = "xcodeProjectPath" ;
689
+
690
+ beforeEach ( ( ) => {
691
+ const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
692
+ childProcess . exec = async ( command : string , options ?: any , execOptions ?: IExecOptions ) : Promise < any > => null ;
693
+ childProcess . spawnFromEvent = async ( command : string , args : string [ ] , event : string , options ?: any , spawnFromEventOptions ?: ISpawnFromEventOptions ) : Promise < ISpawnResult > => ( {
694
+ stdout : "" ,
695
+ stderr : "" ,
696
+ exitCode : 0
697
+ } ) ;
698
+
699
+ const xcprojService = testInjector . resolve < IXcprojService > ( "xcprojService" ) ;
700
+ xcprojService . verifyXcproj = async ( shouldFail : boolean ) : Promise < boolean > => false ;
701
+ xcprojService . getXcprojInfo = async ( ) : Promise < IXcprojInfo > => ( < any > { } ) ;
702
+ } ) ;
703
+
704
+ it ( "fails when pod executable is not found" , async ( ) => {
705
+ const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
706
+ childProcess . exec = async ( command : string , options ?: any , execOptions ?: IExecOptions ) : Promise < any > => {
707
+ assert . equal ( command , "which pod" ) ;
708
+ throw new Error ( "Missing pod executable" ) ;
709
+ } ;
710
+
711
+ await assert . isRejected ( cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) , "CocoaPods or ruby gem 'xcodeproj' is not installed. Run `sudo gem install cocoapods` and try again." ) ;
712
+ } ) ;
713
+
714
+ it ( "fails when xcodeproj executable is not found" , async ( ) => {
715
+ const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
716
+ childProcess . exec = async ( command : string , options ?: any , execOptions ?: IExecOptions ) : Promise < any > => {
717
+ if ( command === "which pod" ) {
718
+ return ;
719
+ }
720
+
721
+ assert . equal ( command , "which xcodeproj" ) ;
722
+ throw new Error ( "Missing xcodeproj executable" ) ;
723
+
724
+ } ;
725
+
726
+ await assert . isRejected ( cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) , "CocoaPods or ruby gem 'xcodeproj' is not installed. Run `sudo gem install cocoapods` and try again." ) ;
727
+ } ) ;
728
+
729
+ it ( "fails with correct error when xcprojService.verifyXcproj throws" , async ( ) => {
730
+ const expectedError = new Error ( "err" ) ;
731
+ const xcprojService = testInjector . resolve < IXcprojService > ( "xcprojService" ) ;
732
+ xcprojService . verifyXcproj = async ( shouldFail : boolean ) : Promise < boolean > => {
733
+ throw expectedError ;
734
+ } ;
735
+
736
+ await assert . isRejected ( cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) , expectedError ) ;
737
+ } ) ;
738
+
739
+ [ "pod" , "sandbox-pod" ] . forEach ( podExecutable => {
740
+ it ( `uses ${ podExecutable } executable when USE_POD_SANDBOX is ${ podExecutable === "sandbox-pod" } ` , async ( ) => {
741
+ const config = testInjector . resolve < IConfiguration > ( "config" ) ;
742
+ config . USE_POD_SANDBOX = podExecutable === "sandbox-pod" ;
743
+ const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
744
+ let commandCalled = "" ;
745
+ childProcess . spawnFromEvent = async ( command : string , args : string [ ] , event : string , options ?: any , spawnFromEventOptions ?: ISpawnFromEventOptions ) : Promise < ISpawnResult > => {
746
+ commandCalled = command ;
747
+ return {
748
+ stdout : "" ,
749
+ stderr : "" ,
750
+ exitCode : 0
751
+ } ;
752
+ } ;
753
+
754
+ await cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) ;
755
+ assert . equal ( commandCalled , podExecutable ) ;
756
+ } ) ;
757
+ } ) ;
758
+
759
+ it ( "calls pod install spawnFromEvent with correct arguments" , async ( ) => {
760
+ const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
761
+ let commandCalled = "" ;
762
+ childProcess . spawnFromEvent = async ( command : string , args : string [ ] , event : string , options ?: any , spawnFromEventOptions ?: ISpawnFromEventOptions ) : Promise < ISpawnResult > => {
763
+ commandCalled = command ;
764
+ assert . deepEqual ( args , [ "install" ] ) ;
765
+ assert . equal ( event , "close" ) ;
766
+ assert . deepEqual ( options , { cwd : projectRoot , stdio : [ 'pipe' , process . stdout , process . stdout ] } ) ;
767
+ assert . deepEqual ( spawnFromEventOptions , { throwError : false } ) ;
768
+ return {
769
+ stdout : "" ,
770
+ stderr : "" ,
771
+ exitCode : 0
772
+ } ;
773
+ } ;
774
+
775
+ await cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) ;
776
+ assert . equal ( commandCalled , "pod" ) ;
777
+ } ) ;
778
+
779
+ it ( "fails when pod install exits with code that is not 0" , async ( ) => {
780
+ const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
781
+ childProcess . spawnFromEvent = async ( command : string , args : string [ ] , event : string , options ?: any , spawnFromEventOptions ?: ISpawnFromEventOptions ) : Promise < ISpawnResult > => {
782
+ return {
783
+ stdout : "" ,
784
+ stderr : "" ,
785
+ exitCode : 1
786
+ } ;
787
+ } ;
788
+
789
+ await assert . isRejected ( cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) , "'pod install' command failed." ) ;
790
+ } ) ;
791
+
792
+ it ( "returns the result of the pod install spawnFromEvent methdo" , async ( ) => {
793
+ const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
794
+ const expectedResult = {
795
+ stdout : "pod install finished" ,
796
+ stderr : "" ,
797
+ exitCode : 0
798
+ } ;
799
+ childProcess . spawnFromEvent = async ( command : string , args : string [ ] , event : string , options ?: any , spawnFromEventOptions ?: ISpawnFromEventOptions ) : Promise < ISpawnResult > => {
800
+ return expectedResult ;
801
+ } ;
802
+
803
+ const result = await cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) ;
804
+ assert . deepEqual ( result , expectedResult ) ;
805
+ } ) ;
806
+
807
+ it ( "executes xcproj command with correct arguments when is true" , async ( ) => {
808
+ const xcprojService = testInjector . resolve < IXcprojService > ( "xcprojService" ) ;
809
+ xcprojService . getXcprojInfo = async ( ) : Promise < IXcprojInfo > => ( < any > {
810
+ shouldUseXcproj : true
811
+ } ) ;
812
+
813
+ const spawnFromEventCalls : any [ ] = [ ] ;
814
+ const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
815
+ childProcess . spawnFromEvent = async ( command : string , args : string [ ] , event : string , options ?: any , spawnFromEventOptions ?: ISpawnFromEventOptions ) : Promise < ISpawnResult > => {
816
+ spawnFromEventCalls . push ( {
817
+ command,
818
+ args,
819
+ event,
820
+ options,
821
+ spawnFromEventOptions
822
+ } ) ;
823
+ return {
824
+ stdout : "" ,
825
+ stderr : "" ,
826
+ exitCode : 0
827
+ } ;
828
+ } ;
829
+
830
+ await cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) ;
831
+ assert . deepEqual ( spawnFromEventCalls , [
832
+ {
833
+ command : "pod" ,
834
+ args : [ "install" ] ,
835
+ event : "close" ,
836
+ options : { cwd : projectRoot , stdio : [ 'pipe' , process . stdout , process . stdout ] } ,
837
+ spawnFromEventOptions : { throwError : false }
838
+ } ,
839
+ {
840
+ command : "xcproj" ,
841
+ args : [ "--project" , xcodeProjPath , "touch" ] ,
842
+ event : "close" ,
843
+ options : undefined ,
844
+ spawnFromEventOptions : undefined
845
+ }
846
+ ] ) ;
847
+
848
+ } ) ;
849
+ } ) ;
685
850
} ) ;
0 commit comments