@@ -97,8 +97,8 @@ exports.IOS = IOS;
97
97
//////////////////////////////////////////////////////////////////////////////////////////
98
98
// EMULATOR MANAGERS
99
99
// bootEmulatorInternal constants
100
- var emulatorMaxReadyAttempts = 5 ;
101
- var emulatorReadyCheckDelayMs = 30 * 1000 ;
100
+ var emulatorMaxReadyAttempts = 50 ;
101
+ var emulatorReadyCheckDelayMs = 5 * 1000 ;
102
102
/**
103
103
* Helper function for EmulatorManager implementations to use to boot an emulator with a given platformName and check, start, and kill methods.
104
104
*/
@@ -117,11 +117,11 @@ function bootEmulatorInternal(platformName, restartEmulators, targetEmulator, ch
117
117
// Dummy command that succeeds if emulator is ready and fails otherwise.
118
118
checkEmulator ( )
119
119
. then ( function ( ) {
120
- checkDeferred . resolve ( undefined ) ;
121
- } , function ( error ) {
122
- console . log ( platformName + " emulator is not ready yet!" ) ;
123
- checkDeferred . reject ( error ) ;
124
- } ) ;
120
+ checkDeferred . resolve ( undefined ) ;
121
+ } , function ( error ) {
122
+ console . log ( platformName + " emulator is not ready yet!" ) ;
123
+ checkDeferred . reject ( error ) ;
124
+ } ) ;
125
125
return checkDeferred . promise ;
126
126
}
127
127
var emulatorReadyAttempts = 0 ;
@@ -137,11 +137,11 @@ function bootEmulatorInternal(platformName, restartEmulators, targetEmulator, ch
137
137
setTimeout ( function ( ) {
138
138
checkEmulatorReady ( )
139
139
. then ( function ( ) {
140
- looperDeferred . resolve ( undefined ) ;
141
- onEmulatorReady ( ) ;
142
- } , function ( ) {
143
- return checkEmulatorReadyLooper ( ) . then ( function ( ) { looperDeferred . resolve ( undefined ) ; } , function ( ) { looperDeferred . reject ( undefined ) ; } ) ;
144
- } ) ;
140
+ looperDeferred . resolve ( undefined ) ;
141
+ onEmulatorReady ( ) ;
142
+ } , function ( ) {
143
+ return checkEmulatorReadyLooper ( ) . then ( function ( ) { looperDeferred . resolve ( undefined ) ; } , function ( ) { looperDeferred . reject ( undefined ) ; } ) ;
144
+ } ) ;
145
145
} , emulatorReadyCheckDelayMs ) ;
146
146
return looperDeferred . promise ;
147
147
}
@@ -168,6 +168,7 @@ var AndroidEmulatorManager = (function () {
168
168
* Returns the target emulator, which is specified through the command line.
169
169
*/
170
170
AndroidEmulatorManager . prototype . getTargetEmulator = function ( ) {
171
+ let _this = this ;
171
172
if ( this . targetEmulator )
172
173
return Q ( this . targetEmulator ) ;
173
174
else {
@@ -177,22 +178,22 @@ var AndroidEmulatorManager = (function () {
177
178
// If no Android simulator is specified, get the most recent Android simulator to run tests on.
178
179
testUtil_1 . TestUtil . getProcessOutput ( "emulator -list-avds" , { noLogCommand : true , noLogStdOut : true , noLogStdErr : true } )
179
180
. then ( ( Devices ) => {
180
- const listOfDevices = Devices . trim ( ) . split ( "\n" ) ;
181
- deferred . resolve ( listOfDevices [ listOfDevices . length - 1 ] ) ;
182
- } , ( error ) => {
183
- deferred . reject ( error ) ;
184
- } ) ;
181
+ const listOfDevices = Devices . trim ( ) . split ( "\n" ) ;
182
+ deferred . resolve ( listOfDevices [ listOfDevices . length - 1 ] ) ;
183
+ } , ( error ) => {
184
+ deferred . reject ( error ) ;
185
+ } ) ;
185
186
}
186
187
else {
187
188
// Use the simulator specified on the command line.
188
189
deferred . resolve ( targetAndroidEmulator ) ;
189
190
}
190
191
return deferred . promise
191
192
. then ( ( targetEmulator ) => {
192
- this . targetEmulator = targetEmulator ;
193
- console . log ( "Using Android simulator named " + this . targetEmulator ) ;
194
- return this . targetEmulator ;
195
- } ) ;
193
+ _this . targetEmulator = targetEmulator ;
194
+ console . log ( "Using Android simulator named " + _this . targetEmulator ) ;
195
+ return _this . targetEmulator ;
196
+ } ) ;
196
197
}
197
198
} ;
198
199
/**
@@ -205,15 +206,22 @@ var AndroidEmulatorManager = (function () {
205
206
return testUtil_1 . TestUtil . getProcessOutput ( "adb shell pm list packages" , { noLogCommand : true , noLogStdOut : true , noLogStdErr : true } ) . then ( function ( ) { return null ; } ) ;
206
207
}
207
208
function startAndroidEmulator ( androidEmulatorName ) {
208
- return testUtil_1 . TestUtil . getProcessOutput ( "emulator @" + androidEmulatorName ) . then ( function ( ) { return null ; } ) ;
209
+ const androidEmulatorCommand = `emulator @${ androidEmulatorName } ` ;
210
+ let osSpecificCommand = "" ;
211
+ if ( process . platform === "darwin" ) {
212
+ osSpecificCommand = `${ androidEmulatorCommand } &` ;
213
+ } else {
214
+ osSpecificCommand = `START /B ${ androidEmulatorCommand } ` ;
215
+ }
216
+ return testUtil_1 . TestUtil . getProcessOutput ( osSpecificCommand , { noLogStdErr : true , timeout : 5000 } ) ;
209
217
}
210
218
function killAndroidEmulator ( ) {
211
219
return testUtil_1 . TestUtil . getProcessOutput ( "adb emu kill" ) . then ( function ( ) { return null ; } ) ;
212
220
}
213
221
return this . getTargetEmulator ( )
214
222
. then ( function ( targetEmulator ) {
215
- return bootEmulatorInternal ( "Android" , restartEmulators , targetEmulator , checkAndroidEmulator , startAndroidEmulator , killAndroidEmulator ) ;
216
- } ) ;
223
+ return bootEmulatorInternal ( "Android" , restartEmulators , targetEmulator , checkAndroidEmulator , startAndroidEmulator , killAndroidEmulator ) ;
224
+ } ) ;
217
225
} ;
218
226
/**
219
227
* Launches an already installed application by app id.
@@ -234,12 +242,12 @@ var AndroidEmulatorManager = (function () {
234
242
var _this = this ;
235
243
return this . endRunningApplication ( appId )
236
244
. then ( function ( ) {
237
- // Wait for a second before restarting.
238
- return Q . delay ( 1000 ) ;
239
- } )
245
+ // Wait for a second before restarting.
246
+ return Q . delay ( 1000 ) ;
247
+ } )
240
248
. then ( function ( ) {
241
- return _this . launchInstalledApplication ( appId ) ;
242
- } ) ;
249
+ return _this . launchInstalledApplication ( appId ) ;
250
+ } ) ;
243
251
} ;
244
252
/**
245
253
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
@@ -250,13 +258,13 @@ var AndroidEmulatorManager = (function () {
250
258
// Open a default Android app (for example, settings).
251
259
return this . launchInstalledApplication ( "com.android.settings" )
252
260
. then ( function ( ) {
253
- console . log ( "Waiting for " + delayBeforeResumingMs + "ms before resuming the test application." ) ;
254
- return Q . delay ( delayBeforeResumingMs ) ;
255
- } )
261
+ console . log ( "Waiting for " + delayBeforeResumingMs + "ms before resuming the test application." ) ;
262
+ return Q . delay ( delayBeforeResumingMs ) ;
263
+ } )
256
264
. then ( function ( ) {
257
- // Reopen the app.
258
- return _this . launchInstalledApplication ( appId ) ;
259
- } ) ;
265
+ // Reopen the app.
266
+ return _this . launchInstalledApplication ( appId ) ;
267
+ } ) ;
260
268
} ;
261
269
/**
262
270
* Prepares the emulator for a test.
@@ -284,34 +292,34 @@ var IOSEmulatorManager = (function () {
284
292
* Returns the target emulator, which is specified through the command line.
285
293
*/
286
294
IOSEmulatorManager . prototype . getTargetEmulator = function ( ) {
287
- var _this = this ;
295
+ let _this = this ;
288
296
if ( this . targetEmulator )
289
297
return Q ( this . targetEmulator ) ;
290
298
else {
291
- var deferred = Q . defer ( ) ;
292
- var targetIOSEmulator = testUtil_1 . TestUtil . readMochaCommandLineOption ( IOSEmulatorManager . IOS_EMULATOR_OPTION_NAME ) ;
299
+ let deferred = Q . defer ( ) ;
300
+ let targetIOSEmulator = testUtil_1 . TestUtil . readMochaCommandLineOption ( IOSEmulatorManager . IOS_EMULATOR_OPTION_NAME ) ;
293
301
if ( ! targetIOSEmulator ) {
294
302
// If no iOS simulator is specified, get the most recent iOS simulator to run tests on.
295
303
testUtil_1 . TestUtil . getProcessOutput ( "xcrun simctl list" , { noLogCommand : true , noLogStdOut : true , noLogStdErr : true } )
296
- . then ( function ( listOfDevicesWithDevicePairs ) {
297
- var listOfDevices = listOfDevicesWithDevicePairs . slice ( listOfDevicesWithDevicePairs . indexOf ( "-- iOS" ) , listOfDevicesWithDevicePairs . indexOf ( "-- tvOS" ) ) ;
298
- var phoneDevice = / i P h o n e ( \S * ) * ( \( ( [ 0 - 9 A - Z - ] * ) \) ) / g;
299
- var match = listOfDevices . match ( phoneDevice ) ;
300
- deferred . resolve ( match [ match . length - 1 ] ) ;
301
- } , function ( error ) {
302
- deferred . reject ( error ) ;
303
- } ) ;
304
+ . then ( ( listOfDevicesWithDevicePairs ) => {
305
+ let listOfDevices = listOfDevicesWithDevicePairs . slice ( listOfDevicesWithDevicePairs . indexOf ( "-- iOS" ) , listOfDevicesWithDevicePairs . indexOf ( "-- tvOS" ) ) ;
306
+ let phoneDevice = / i P h o n e ( \S * ) * ( \( ( [ 0 - 9 A - Z - ] * ) \) ) / g;
307
+ let match = listOfDevices . match ( phoneDevice ) ;
308
+ deferred . resolve ( match [ match . length - 1 ] ) ;
309
+ } , ( error ) => {
310
+ deferred . reject ( error ) ;
311
+ } ) ;
304
312
}
305
313
else {
306
314
// Use the simulator specified on the command line.
307
315
deferred . resolve ( targetIOSEmulator ) ;
308
316
}
309
317
return deferred . promise
310
- . then ( function ( targetEmulator ) {
311
- _this . targetEmulator = targetEmulator ;
312
- console . log ( "Using iOS simulator named " + _this . targetEmulator ) ;
313
- return _this . targetEmulator ;
314
- } ) ;
318
+ . then ( ( targetEmulator ) => {
319
+ _this . targetEmulator = targetEmulator ;
320
+ console . log ( "Using iOS simulator named " + _this . targetEmulator ) ;
321
+ return _this . targetEmulator ;
322
+ } ) ;
315
323
}
316
324
} ;
317
325
/**
@@ -332,8 +340,8 @@ var IOSEmulatorManager = (function () {
332
340
}
333
341
return this . getTargetEmulator ( )
334
342
. then ( function ( targetEmulator ) {
335
- return bootEmulatorInternal ( "iOS" , restartEmulators , targetEmulator , checkIOSEmulator , startIOSEmulator , killIOSEmulator ) ;
336
- } ) ;
343
+ return bootEmulatorInternal ( "iOS" , restartEmulators , targetEmulator , checkIOSEmulator , startIOSEmulator , killIOSEmulator ) ;
344
+ } ) ;
337
345
} ;
338
346
/**
339
347
* Launches an already installed application by app id.
@@ -354,9 +362,9 @@ var IOSEmulatorManager = (function () {
354
362
var _this = this ;
355
363
return this . endRunningApplication ( appId )
356
364
. then ( function ( ) {
357
- // Wait for a second before restarting.
358
- return Q . delay ( 1000 ) ;
359
- } )
365
+ // Wait for a second before restarting.
366
+ return Q . delay ( 1000 ) ;
367
+ } )
360
368
. then ( function ( ) { return _this . launchInstalledApplication ( appId ) ; } ) ;
361
369
} ;
362
370
/**
@@ -368,13 +376,13 @@ var IOSEmulatorManager = (function () {
368
376
// Open a default iOS app (for example, settings).
369
377
return this . launchInstalledApplication ( "com.apple.Preferences" )
370
378
. then ( function ( ) {
371
- console . log ( "Waiting for " + delayBeforeResumingMs + "ms before resuming the test application." ) ;
372
- return Q . delay ( delayBeforeResumingMs ) ;
373
- } )
379
+ console . log ( "Waiting for " + delayBeforeResumingMs + "ms before resuming the test application." ) ;
380
+ return Q . delay ( delayBeforeResumingMs ) ;
381
+ } )
374
382
. then ( function ( ) {
375
- // Reopen the app.
376
- return _this . launchInstalledApplication ( appId ) ;
377
- } ) ;
383
+ // Reopen the app.
384
+ return _this . launchInstalledApplication ( appId ) ;
385
+ } ) ;
378
386
} ;
379
387
/**
380
388
* Prepares the emulator for a test.
0 commit comments