@@ -23,6 +23,8 @@ const rewire = require('rewire');
2323const { CordovaError } = require ( 'cordova-common' ) ;
2424const build = rewire ( '../../lib/build' ) ;
2525
26+ const realBuild = require ( '../../lib/build' ) ;
27+
2628describe ( 'build' , ( ) => {
2729 const testProjectPath = path . join ( '/test' , 'project' , 'path' ) ;
2830
@@ -31,7 +33,7 @@ describe('build', () => {
3133 build . __set__ ( '__dirname' , path . join ( '/test' , 'dir' ) ) ;
3234
3335 it ( 'should generate appropriate args if a single buildFlag is passed in' , ( ) => {
34- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , '' , { device : true , buildFlag : '' } ) ;
36+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , { device : true , buildFlag : '' } ) ;
3537 expect ( args ) . toEqual ( [
3638 '-workspace' ,
3739 'App.xcworkspace' ,
@@ -61,7 +63,7 @@ describe('build', () => {
6163 '-resultBundlePath="/tmp/result bundle/file"'
6264 ] ;
6365
64- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , '' , { device : true , buildFlag : buildFlags } ) ;
66+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , { device : true , buildFlag : buildFlags } ) ;
6567 expect ( args ) . toEqual ( [
6668 '-workspace' ,
6769 'TestWorkspaceFlag' ,
@@ -83,7 +85,7 @@ describe('build', () => {
8385 } ) ;
8486
8587 it ( 'should generate appropriate args for device' , ( ) => {
86- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , '' , { device : true } ) ;
88+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , { device : true } ) ;
8789 expect ( args ) . toEqual ( [
8890 '-workspace' ,
8991 'App.xcworkspace' ,
@@ -101,7 +103,7 @@ describe('build', () => {
101103 } ) ;
102104
103105 it ( 'should generate appropriate args for simulator' , ( ) => {
104- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , 'iPhone 5s' , { device : false } ) ;
106+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , { device : false } ) ;
105107 expect ( args ) . toEqual ( [
106108 '-workspace' ,
107109 'App.xcworkspace' ,
@@ -112,7 +114,7 @@ describe('build', () => {
112114 '-sdk' ,
113115 'iphonesimulator' ,
114116 '-destination' ,
115- 'platform=iOS Simulator,name=iPhone 5s ' ,
117+ 'generic/ platform=iOS Simulator' ,
116118 'build'
117119 ] ) ;
118120 expect ( args . length ) . toEqual ( 11 ) ;
@@ -129,7 +131,7 @@ describe('build', () => {
129131 'SHARED_PRECOMPS_DIR=TestSharedPrecompsDirFlag'
130132 ] ;
131133
132- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , 'iPhone 5s' , { device : false , buildFlag : buildFlags } ) ;
134+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , { device : false , buildFlag : buildFlags } ) ;
133135 expect ( args ) . toEqual ( [
134136 '-workspace' ,
135137 'TestWorkspaceFlag' ,
@@ -153,7 +155,7 @@ describe('build', () => {
153155 it ( 'should add matched flags that are not overriding for device' , ( ) => {
154156 const buildFlags = '-sdk TestSdkFlag' ;
155157
156- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , '' , { device : true , buildFlag : buildFlags } ) ;
158+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , { device : true , buildFlag : buildFlags } ) ;
157159 expect ( args ) . toEqual ( [
158160 '-workspace' ,
159161 'App.xcworkspace' ,
@@ -175,7 +177,7 @@ describe('build', () => {
175177 it ( 'should add matched flags that are not overriding for simulator' , ( ) => {
176178 const buildFlags = '-archivePath TestArchivePathFlag' ;
177179
178- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , 'iPhone 5s' , { device : false , buildFlag : buildFlags } ) ;
180+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , { device : false , buildFlag : buildFlags } ) ;
179181 expect ( args ) . toEqual ( [
180182 '-workspace' ,
181183 'App.xcworkspace' ,
@@ -186,7 +188,7 @@ describe('build', () => {
186188 '-sdk' ,
187189 'iphonesimulator' ,
188190 '-destination' ,
189- 'platform=iOS Simulator,name=iPhone 5s ' ,
191+ 'generic/ platform=iOS Simulator' ,
190192 'build' ,
191193 '-archivePath' ,
192194 'TestArchivePathFlag'
@@ -203,7 +205,7 @@ describe('build', () => {
203205 authenticationKeyIssuerID : '00000000-0000-0000-0000-000000000000'
204206 } ;
205207
206- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , '' , buildOpts ) ;
208+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , buildOpts ) ;
207209 expect ( args ) . toEqual ( [
208210 '-workspace' ,
209211 'App.xcworkspace' ,
@@ -232,7 +234,7 @@ describe('build', () => {
232234 catalyst : true
233235 } ;
234236
235- const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , '' , buildOpts ) ;
237+ const args = getXcodeBuildArgs ( testProjectPath , 'TestConfiguration' , buildOpts ) ;
236238 expect ( args ) . toEqual ( [
237239 '-workspace' ,
238240 'App.xcworkspace' ,
@@ -479,53 +481,23 @@ describe('build', () => {
479481 } ) ;
480482 } ) ;
481483
482- describe ( 'getDefaultSimulatorTarget method' , ( ) => {
483- it ( 'should find iPhone X as the default simulator target.' , ( ) => {
484- const mockedEmulators = [ {
485- name : 'iPhone 7' ,
486- identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-7' ,
487- simIdentifier : 'iPhone-7'
488- } ,
489- {
490- name : 'iPhone 8' ,
491- identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-8' ,
492- simIdentifier : 'iPhone-8'
493- } ,
494- {
495- name : 'iPhone X' ,
496- identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-X' ,
497- simIdentifier : 'iPhone-X'
498- } ] ;
499-
500- // This method will require a module that supports the run method.
501- build . __set__ ( 'require' , ( ) => ( {
502- run : ( ) => Promise . resolve ( mockedEmulators )
503- } ) ) ;
504-
505- const getDefaultSimulatorTarget = build . __get__ ( 'getDefaultSimulatorTarget' ) ;
506-
507- return getDefaultSimulatorTarget ( ) . then ( actual => {
508- expect ( actual ) . toEqual ( {
509- name : 'iPhone X' ,
510- identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-X' ,
511- simIdentifier : 'iPhone-X'
512- } ) ;
513- } ) ;
484+ describe ( 'run method' , ( ) => {
485+ it ( 'should not accept debug and release options together' , ( ) => {
486+ return expectAsync ( realBuild . run ( { debug : true , release : true } ) )
487+ . toBeRejectedWithError ( CordovaError , 'Cannot specify "debug" and "release" options together.' ) ;
514488 } ) ;
515489
516- it ( 'should handle the case of no simulators being available' , ( ) => {
517- // This method will require a module that supports the run method.
518- build . __set__ ( 'require' , ( ) => ( {
519- run : ( ) => Promise . resolve ( [ ] )
520- } ) ) ;
490+ it ( 'should not accept device and emulator options together' , ( ) => {
491+ return expectAsync ( realBuild . run ( { device : true , emulator : true } ) )
492+ . toBeRejectedWithError ( CordovaError , 'Cannot specify "device" and "emulator" options together.' ) ;
493+ } ) ;
521494
522- const getDefaultSimulatorTarget = build . __get__ ( 'getDefaultSimulatorTarget' ) ;
495+ it ( 'should not accept a build config file that does not exist' , ( ) => {
496+ spyOn ( fs , 'existsSync' ) . and . returnValue ( false ) ;
497+ const buildConfig = './some/config/path' ;
523498
524- return getDefaultSimulatorTarget ( ) . then ( sim => {
525- return Promise . reject ( new Error ( 'Should not resolve if no simulators are present' ) ) ;
526- } , ( err ) => {
527- expect ( err ) . toBeInstanceOf ( CordovaError ) ;
528- } ) ;
499+ return expectAsync ( realBuild . run ( { buildConfig : './some/config/path' } ) )
500+ . toBeRejectedWithError ( CordovaError , `Build config file does not exist: ${ buildConfig } ` ) ;
529501 } ) ;
530502 } ) ;
531503} ) ;
0 commit comments