@@ -340,4 +340,229 @@ describe('build', function () {
340340 done ( ) ;
341341 } ) ;
342342 } ) ;
343+
344+ describe ( 'help method' , ( ) => {
345+ it ( 'should log a bunch of options' , ( ) => {
346+ const logSpy = jasmine . createSpy ( ) ;
347+ const procStub = { exit : _ => null , cwd : _ => '' , argv : [ '' , '' ] } ;
348+ build . __set__ ( { console : { log : logSpy } , process : procStub } ) ;
349+
350+ build . help ( ) ;
351+ expect ( logSpy ) . toHaveBeenCalledWith ( jasmine . stringMatching ( / ^ U s a g e : / ) ) ;
352+ } ) ;
353+ } ) ;
354+
355+ describe ( 'run method' , ( ) => {
356+ let rejectSpy ;
357+
358+ beforeEach ( ( ) => {
359+ rejectSpy = jasmine . createSpy ( 'reject' ) ;
360+
361+ build . __set__ ( 'Q' , {
362+ reject : rejectSpy
363+ } ) ;
364+ } ) ;
365+
366+ it ( 'should not accept debug and release options together' , ( ) => {
367+ build . run ( {
368+ debug : true ,
369+ release : true
370+ } ) ;
371+
372+ expect ( rejectSpy ) . toHaveBeenCalledWith ( 'Cannot specify "debug" and "release" options together.' ) ;
373+ } ) ;
374+
375+ it ( 'should not accept device and emulator options together' , ( ) => {
376+ build . run ( {
377+ device : true ,
378+ emulator : true
379+ } ) ;
380+
381+ expect ( rejectSpy ) . toHaveBeenCalledWith ( 'Cannot specify "device" and "emulator" options together.' ) ;
382+ } ) ;
383+
384+ it ( 'should reject when build config file missing' , ( ) => {
385+ const existsSyncSpy = jasmine . createSpy ( 'existsSync' ) . and . returnValue ( false ) ;
386+ build . __set__ ( 'fs' , {
387+ existsSync : existsSyncSpy
388+ } ) ;
389+
390+ build . run ( {
391+ buildConfig : './some/config/path'
392+ } ) ;
393+
394+ expect ( rejectSpy ) . toHaveBeenCalledWith ( jasmine . stringMatching ( / ^ B u i l d c o n f i g f i l e d o e s n o t e x i s t : / ) ) ;
395+ } ) ;
396+ } ) ;
397+
398+ describe ( 'getDefaultSimulatorTarget method' , ( ) => {
399+ it ( 'should find iPhone X as the default simulator target.' , ( done ) => {
400+ const mockedEmulators = [ {
401+ name : 'iPhone 5s' ,
402+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-5s' ,
403+ simIdentifier : 'iPhone-5s'
404+ } ,
405+ {
406+ name : 'iPhone 6' ,
407+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-6' ,
408+ simIdentifier : 'iPhone-6'
409+ } ,
410+ {
411+ name : 'iPhone 6 Plus' ,
412+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus' ,
413+ simIdentifier : 'iPhone-6-Plus'
414+ } ,
415+ {
416+ name : 'iPhone 6s' ,
417+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-6s' ,
418+ simIdentifier : 'iPhone-6s'
419+ } ,
420+ {
421+ name : 'iPhone 6s Plus' ,
422+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-6s-Plus' ,
423+ simIdentifier : 'iPhone-6s-Plus'
424+ } ,
425+ {
426+ name : 'iPhone 7' ,
427+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-7' ,
428+ simIdentifier : 'iPhone-7'
429+ } ,
430+ {
431+ name : 'iPhone 7 Plus' ,
432+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-7-Plus' ,
433+ simIdentifier : 'iPhone-7-Plus'
434+ } ,
435+ {
436+ name : 'iPhone 8' ,
437+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-8' ,
438+ simIdentifier : 'iPhone-8'
439+ } ,
440+ {
441+ name : 'iPhone 8 Plus' ,
442+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-8-Plus' ,
443+ simIdentifier : 'iPhone-8-Plus'
444+ } ,
445+ {
446+ name : 'iPhone SE' ,
447+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-SE' ,
448+ simIdentifier : 'iPhone-SE'
449+ } ,
450+ {
451+ name : 'iPhone X' ,
452+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-X' ,
453+ simIdentifier : 'iPhone-X'
454+ } ,
455+ {
456+ name : 'iPad Air' ,
457+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPad-Air' ,
458+ simIdentifier : 'iPad-Air'
459+ } ,
460+ {
461+ name : 'iPad Air 2' ,
462+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPad-Air-2' ,
463+ simIdentifier : 'iPad-Air-2'
464+ } ,
465+ {
466+ name : 'iPad (5th generation)' ,
467+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPad--5th-generation-' ,
468+ simIdentifier : 'iPad--5th-generation-'
469+ } ] ;
470+
471+ // This method will require a module that supports the run method.
472+ build . __set__ ( 'require' , ( ) => {
473+ return {
474+ run : ( ) => {
475+ return new Promise ( ( resolve , reject ) => {
476+ resolve ( mockedEmulators ) ;
477+ } ) ;
478+ }
479+ } ;
480+ } ) ;
481+
482+ const getDefaultSimulatorTarget = build . __get__ ( 'getDefaultSimulatorTarget' ) ;
483+ const exec = getDefaultSimulatorTarget ( ) ;
484+
485+ const expected = {
486+ name : 'iPhone X' ,
487+ identifier : 'com.apple.CoreSimulator.SimDeviceType.iPhone-X' ,
488+ simIdentifier : 'iPhone-X'
489+ } ;
490+
491+ exec . then ( ( actual ) => {
492+ expect ( actual ) . toEqual ( expected ) ;
493+ done ( ) ;
494+ } ) ;
495+ } ) ;
496+ } ) ;
497+
498+ describe ( 'findXCodeProjectIn method' , ( ) => {
499+ let findXCodeProjectIn ;
500+ let shellLsSpy ;
501+ let rejectSpy ;
502+ let resolveSpy ;
503+ let emitSpy ;
504+ const fakePath = '/path/foobar' ;
505+
506+ beforeEach ( ( ) => {
507+ findXCodeProjectIn = build . __get__ ( 'findXCodeProjectIn' ) ;
508+
509+ // Shell Spy
510+ shellLsSpy = jasmine . createSpy ( 'shellLsSpy' ) ;
511+ build . __set__ ( 'shell' , {
512+ ls : shellLsSpy
513+ } ) ;
514+
515+ // Q Spy
516+ rejectSpy = jasmine . createSpy ( 'rejectSpy' ) ;
517+ resolveSpy = jasmine . createSpy ( 'resolveSpy' ) ;
518+ build . __set__ ( 'Q' , {
519+ reject : rejectSpy ,
520+ resolve : resolveSpy
521+ } ) ;
522+
523+ // Events spy
524+ emitSpy = jasmine . createSpy ( 'emitSpy' ) ;
525+ build . __set__ ( 'events' , {
526+ emit : emitSpy
527+ } ) ;
528+ } ) ;
529+
530+ it ( 'should find not find Xcode project' , ( ) => {
531+ shellLsSpy . and . returnValue ( [ 'README.md' ] ) ;
532+
533+ findXCodeProjectIn ( fakePath ) ;
534+
535+ expect ( rejectSpy ) . toHaveBeenCalledWith ( 'No Xcode project found in ' + fakePath ) ;
536+ } ) ;
537+
538+ it ( 'should emit finding multiple Xcode projects' , ( ) => {
539+ shellLsSpy . and . returnValue ( [ 'Test1.xcodeproj' , 'Test2.xcodeproj' ] ) ;
540+
541+ findXCodeProjectIn ( fakePath ) ;
542+
543+ // Emit
544+ let actualEmit = emitSpy . calls . argsFor ( 0 ) [ 1 ] ;
545+ expect ( emitSpy ) . toHaveBeenCalled ( ) ;
546+ expect ( actualEmit ) . toContain ( 'Found multiple .xcodeproj directories in' ) ;
547+
548+ // Resolve
549+ let actualResolve = resolveSpy . calls . argsFor ( 0 ) [ 0 ] ;
550+ expect ( resolveSpy ) . toHaveBeenCalled ( ) ;
551+ expect ( actualResolve ) . toContain ( 'Test1' ) ;
552+ } ) ;
553+
554+ it ( 'should detect and return only one projects' , ( ) => {
555+ shellLsSpy . and . returnValue ( [ 'Test1.xcodeproj' ] ) ;
556+
557+ findXCodeProjectIn ( fakePath ) ;
558+
559+ // Emit
560+ expect ( emitSpy ) . not . toHaveBeenCalled ( ) ;
561+
562+ // Resolve
563+ let actualResolve = resolveSpy . calls . argsFor ( 0 ) [ 0 ] ;
564+ expect ( resolveSpy ) . toHaveBeenCalled ( ) ;
565+ expect ( actualResolve ) . toContain ( 'Test1' ) ;
566+ } ) ;
567+ } ) ;
343568} ) ;
0 commit comments