@@ -113,10 +113,11 @@ function bootEmulatorInternal(platformName, restartEmulators, targetEmulator, ch
113113 var checkDeferred = Q . defer ( ) ;
114114 console . log ( "Checking if " + platformName + " emulator is ready yet..." ) ;
115115 // Dummy command that succeeds if emulator is ready and fails otherwise.
116- checkEmulator ( )
116+ checkEmulator ( targetEmulator )
117117 . then ( function ( ) {
118118 checkDeferred . resolve ( undefined ) ;
119119 } , function ( error ) {
120+ console . info ( error ) ;
120121 console . log ( platformName + " emulator is not ready yet!" ) ;
121122 checkDeferred . reject ( error ) ;
122123 } ) ;
@@ -198,7 +199,7 @@ var AndroidEmulatorManager = (function () {
198199 * Boots the target emulator.
199200 */
200201 AndroidEmulatorManager . prototype . bootEmulator = function ( restartEmulators ) {
201- function checkAndroidEmulator ( ) {
202+ function checkAndroidEmulator ( androidEmulatorName ) {
202203 // A command that does nothing but only succeeds if the emulator is running.
203204 // List all of the packages on the device.
204205 return testUtil_1 . TestUtil . getProcessOutput ( "adb shell pm list packages" , { noLogCommand : true , noLogStdOut : true , noLogStdErr : true } ) . then ( function ( ) { return null ; } ) ;
@@ -300,9 +301,9 @@ var IOSEmulatorManager = (function () {
300301 testUtil_1 . TestUtil . getProcessOutput ( "xcrun simctl list" , { noLogCommand : true , noLogStdOut : true , noLogStdErr : true } )
301302 . then ( ( listOfDevicesWithDevicePairs ) => {
302303 let listOfDevices = listOfDevicesWithDevicePairs . slice ( listOfDevicesWithDevicePairs . indexOf ( "-- iOS" ) , listOfDevicesWithDevicePairs . indexOf ( "-- tvOS" ) ) ;
303- let phoneDevice = / i P h o n e ( \S * ) * ( \( ( [ 0 - 9 A - Z - ] * ) \) ) / g;
304- let match = listOfDevices . match ( phoneDevice ) ;
305- deferred . resolve ( match [ match . length - 1 ] ) ;
304+ let phoneDevice = / i P h o n e \ \S * \ ? . * ? \( ( [ 0 - 9 A - Z - ] * ) \) / g;
305+ let match = phoneDevice . exec ( listOfDevices ) ;
306+ deferred . resolve ( match [ 1 ] ) ;
306307 } , ( error ) => {
307308 deferred . reject ( error ) ;
308309 } ) ;
@@ -323,17 +324,18 @@ var IOSEmulatorManager = (function () {
323324 * Boots the target emulator.
324325 */
325326 IOSEmulatorManager . prototype . bootEmulator = function ( restartEmulators ) {
326- function checkIOSEmulator ( ) {
327+ function checkIOSEmulator ( iOSEmulatorId ) {
327328 // A command that does nothing but only succeeds if the emulator is running.
328- // Get the environment variable with the name "asdf" (return null, not an error, if not initialized).
329- return testUtil_1 . TestUtil . getProcessOutput ( "xcrun simctl getenv booted asdf" , { noLogCommand : true , noLogStdOut : true , noLogStdErr : true } ) . then ( function ( ) { return null ; } ) ;
329+ return testUtil_1 . TestUtil . getProcessOutput ( "xcrun simctl getenv booted SIMULATOR_UDID" , { noLogCommand : true , noLogStdOut : true , noLogStdErr : true } ) . then ( function ( simUdid ) {
330+ return simUdid . trim ( ) == iOSEmulatorId . trim ( ) ? true : Promise . reject ( new Error ( 'Waiting for device to boot' ) ) ;
331+ } ) ;
330332 }
331- function startIOSEmulator ( iOSEmulatorName ) {
332- return testUtil_1 . TestUtil . getProcessOutput ( "xcrun instruments -w \"" + iOSEmulatorName + "\"" , { noLogStdErr : true } )
333+ function startIOSEmulator ( iOSEmulatorId ) {
334+ return testUtil_1 . TestUtil . getProcessOutput ( "xcrun simctl boot " + iOSEmulatorId , { noLogStdErr : true } )
333335 . catch ( function ( error ) { return undefined ; /* Always fails because we do not specify a template, which is not necessary to just start the emulator */ } ) . then ( function ( ) { return null ; } ) ;
334336 }
335337 function killIOSEmulator ( ) {
336- return testUtil_1 . TestUtil . getProcessOutput ( "killall Simulator " ) . then ( function ( ) { return null ; } ) ;
338+ return testUtil_1 . TestUtil . getProcessOutput ( "xcrun simctl shutdown all " ) . then ( function ( ) { return null ; } ) ;
337339 }
338340 return this . getTargetEmulator ( )
339341 . then ( function ( targetEmulator ) {
0 commit comments