Skip to content

Commit 2e85db6

Browse files
authored
[Tests] Fix broken tests (#1784)
1 parent 6ffa5ff commit 2e85db6

File tree

2 files changed

+89
-81
lines changed

2 files changed

+89
-81
lines changed

code-push-plugin-testing-framework/script/platform.js

+70-62
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ exports.IOS = IOS;
9797
//////////////////////////////////////////////////////////////////////////////////////////
9898
// EMULATOR MANAGERS
9999
// bootEmulatorInternal constants
100-
var emulatorMaxReadyAttempts = 5;
101-
var emulatorReadyCheckDelayMs = 30 * 1000;
100+
var emulatorMaxReadyAttempts = 50;
101+
var emulatorReadyCheckDelayMs = 5 * 1000;
102102
/**
103103
* Helper function for EmulatorManager implementations to use to boot an emulator with a given platformName and check, start, and kill methods.
104104
*/
@@ -117,11 +117,11 @@ function bootEmulatorInternal(platformName, restartEmulators, targetEmulator, ch
117117
// Dummy command that succeeds if emulator is ready and fails otherwise.
118118
checkEmulator()
119119
.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+
});
125125
return checkDeferred.promise;
126126
}
127127
var emulatorReadyAttempts = 0;
@@ -137,11 +137,11 @@ function bootEmulatorInternal(platformName, restartEmulators, targetEmulator, ch
137137
setTimeout(function () {
138138
checkEmulatorReady()
139139
.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+
});
145145
}, emulatorReadyCheckDelayMs);
146146
return looperDeferred.promise;
147147
}
@@ -168,6 +168,7 @@ var AndroidEmulatorManager = (function () {
168168
* Returns the target emulator, which is specified through the command line.
169169
*/
170170
AndroidEmulatorManager.prototype.getTargetEmulator = function () {
171+
let _this = this;
171172
if (this.targetEmulator)
172173
return Q(this.targetEmulator);
173174
else {
@@ -177,22 +178,22 @@ var AndroidEmulatorManager = (function () {
177178
// If no Android simulator is specified, get the most recent Android simulator to run tests on.
178179
testUtil_1.TestUtil.getProcessOutput("emulator -list-avds", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true })
179180
.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+
});
185186
}
186187
else {
187188
// Use the simulator specified on the command line.
188189
deferred.resolve(targetAndroidEmulator);
189190
}
190191
return deferred.promise
191192
.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+
});
196197
}
197198
};
198199
/**
@@ -205,15 +206,22 @@ var AndroidEmulatorManager = (function () {
205206
return testUtil_1.TestUtil.getProcessOutput("adb shell pm list packages", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true }).then(function () { return null; });
206207
}
207208
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 });
209217
}
210218
function killAndroidEmulator() {
211219
return testUtil_1.TestUtil.getProcessOutput("adb emu kill").then(function () { return null; });
212220
}
213221
return this.getTargetEmulator()
214222
.then(function (targetEmulator) {
215-
return bootEmulatorInternal("Android", restartEmulators, targetEmulator, checkAndroidEmulator, startAndroidEmulator, killAndroidEmulator);
216-
});
223+
return bootEmulatorInternal("Android", restartEmulators, targetEmulator, checkAndroidEmulator, startAndroidEmulator, killAndroidEmulator);
224+
});
217225
};
218226
/**
219227
* Launches an already installed application by app id.
@@ -234,12 +242,12 @@ var AndroidEmulatorManager = (function () {
234242
var _this = this;
235243
return this.endRunningApplication(appId)
236244
.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+
})
240248
.then(function () {
241-
return _this.launchInstalledApplication(appId);
242-
});
249+
return _this.launchInstalledApplication(appId);
250+
});
243251
};
244252
/**
245253
* 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 () {
250258
// Open a default Android app (for example, settings).
251259
return this.launchInstalledApplication("com.android.settings")
252260
.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+
})
256264
.then(function () {
257-
// Reopen the app.
258-
return _this.launchInstalledApplication(appId);
259-
});
265+
// Reopen the app.
266+
return _this.launchInstalledApplication(appId);
267+
});
260268
};
261269
/**
262270
* Prepares the emulator for a test.
@@ -284,34 +292,34 @@ var IOSEmulatorManager = (function () {
284292
* Returns the target emulator, which is specified through the command line.
285293
*/
286294
IOSEmulatorManager.prototype.getTargetEmulator = function () {
287-
var _this = this;
295+
let _this = this;
288296
if (this.targetEmulator)
289297
return Q(this.targetEmulator);
290298
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);
293301
if (!targetIOSEmulator) {
294302
// If no iOS simulator is specified, get the most recent iOS simulator to run tests on.
295303
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 = /iPhone (\S* )*(\(([0-9A-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 = /iPhone (\S* )*(\(([0-9A-Z-]*)\))/g;
307+
let match = listOfDevices.match(phoneDevice);
308+
deferred.resolve(match[match.length - 1]);
309+
}, (error) => {
310+
deferred.reject(error);
311+
});
304312
}
305313
else {
306314
// Use the simulator specified on the command line.
307315
deferred.resolve(targetIOSEmulator);
308316
}
309317
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+
});
315323
}
316324
};
317325
/**
@@ -332,8 +340,8 @@ var IOSEmulatorManager = (function () {
332340
}
333341
return this.getTargetEmulator()
334342
.then(function (targetEmulator) {
335-
return bootEmulatorInternal("iOS", restartEmulators, targetEmulator, checkIOSEmulator, startIOSEmulator, killIOSEmulator);
336-
});
343+
return bootEmulatorInternal("iOS", restartEmulators, targetEmulator, checkIOSEmulator, startIOSEmulator, killIOSEmulator);
344+
});
337345
};
338346
/**
339347
* Launches an already installed application by app id.
@@ -354,9 +362,9 @@ var IOSEmulatorManager = (function () {
354362
var _this = this;
355363
return this.endRunningApplication(appId)
356364
.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+
})
360368
.then(function () { return _this.launchInstalledApplication(appId); });
361369
};
362370
/**
@@ -368,13 +376,13 @@ var IOSEmulatorManager = (function () {
368376
// Open a default iOS app (for example, settings).
369377
return this.launchInstalledApplication("com.apple.Preferences")
370378
.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+
})
374382
.then(function () {
375-
// Reopen the app.
376-
return _this.launchInstalledApplication(appId);
377-
});
383+
// Reopen the app.
384+
return _this.launchInstalledApplication(appId);
385+
});
378386
};
379387
/**
380388
* Prepares the emulator for a test.

0 commit comments

Comments
 (0)