solve async test messages with immediate problem

This commit is contained in:
scottbommarito
2016-06-01 11:18:48 -07:00
parent 9905c34beb
commit c3e913632d
4 changed files with 44 additions and 53 deletions

View File

@@ -39,11 +39,35 @@ module.exports = {
},
sync: function(testApp, onSyncStatus, onSyncError, options) {
return CodePush.sync(options)
.then((status) => {
return testApp.onSyncStatus(status).then(() => { return onSyncStatus(status); });
}, (error) => {
return testApp.onSyncError(error).then(() => { return onSyncError(error); });
});
return CodePush.checkForUpdate()
.then(
(remotePackage) => {
// Since immediate installs cannot be reliably logged (due to async network calls), we don't log "UPDATE_INSTALLED" when the installation is immediate.
// However, to determine this, we must first figure out whether or not the package is mandatory because mandatory packages use a different install mode than regular updates.
// This requires an additional call to checkForUpdate before syncing.
var regularUpdateIsImmediate = options && options.installMode === CodePush.InstallMode.IMMEDIATE;
var mandatoryUpdateIsImmediate = !options || (options && (!options.mandatoryInstallMode || options.mandatoryInstallMode === CodePush.InstallMode.IMMEDIATE));
var isInstallImmediate = (remotePackage && remotePackage.isMandatory) ? mandatoryUpdateIsImmediate : regularUpdateIsImmediate;
return CodePush.sync(options)
.then((status) => {
if (!(isInstallImmediate && status === CodePush.SyncStatus.UPDATE_INSTALLED)) {
return testApp.onSyncStatus(status).then(() => { return onSyncStatus(status); });
}
return onSyncStatus(status);
}, (error) => {
return testApp.onSyncError(error).then(() => { return onSyncError(error); });
});
},
(error) => {
return CodePush.sync(options)
.then((status) => {
// Should fail because the check for update failed, so no need to check whether the install is immediate.
return testApp.onSyncStatus(status).then(() => { return onSyncStatus(status); });
}, (error) => {
return testApp.onSyncError(error).then(() => { return onSyncError(error); });
});
}
);
}
}

View File

@@ -23,32 +23,6 @@
NSURL *jsCodeLocation;
/**
* Loading JavaScript code - uncomment the one you want.
*
* OPTION 1
* Load from development server. Start the server from the repository root:
*
* $ npm start
*
* To run on device, change `localhost` to the IP address of your computer
* (you can get this by typing `ifconfig` into the terminal and selecting the
* `inet` value under `en0:`) and make sure your computer and iOS device are
* on the same Wi-Fi network.
*/
//jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.includeRequire.runModule.bundle?dev=true&platform=ios"];
/**
* OPTION 2
* Load from pre-bundled file on disk. To re-generate the static bundle
* from the root of your project directory, run
*
* $ react-native bundle --minify
*
* see http://facebook.github.io/react-native/docs/runningondevice.html
*/
jsCodeLocation = [CodePush bundleURL];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation

View File

@@ -133,7 +133,7 @@ class RNAndroid extends Platform.Android implements RNPlatform {
// In order to run on Android without the package manager, we must create a release APK and then sign it with the debug certificate.
var androidDirectory: string = path.join(projectDirectory, PluginTestingFramework.TestAppName, "android");
var apkPath = this.getBinaryPath(projectDirectory);
return TestUtil.getProcessOutput("./gradlew assembleRelease", { cwd: androidDirectory })
return TestUtil.getProcessOutput("./gradlew assembleRelease --daemon", { cwd: androidDirectory })
.then<string>(TestUtil.getProcessOutput.bind(undefined, "jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android " + apkPath + " androiddebugkey", { cwd: androidDirectory, noLogStdOut: true }));
}
}
@@ -240,6 +240,10 @@ class RNIOS extends Platform.IOS implements RNPlatform {
// The first time an iOS project is built, it fails because it does not finish building libReact.a before it builds the test app.
// Simply build again to fix the issue.
if (!RNIOS.iosFirstBuild[projectDirectory]) {
var iosBuildFolder = path.join(iOSProject, "build");
if (fs.existsSync(iosBuildFolder)) {
del.sync([iosBuildFolder], { force: true });
}
RNIOS.iosFirstBuild[projectDirectory] = true;
return this.buildApp(projectDirectory);
}
@@ -435,14 +439,13 @@ class RNProjectManager extends ProjectManager {
return Q<string>(undefined)
.then(() => {
// Build if this scenario has not yet been built.
/* if (!RNProjectManager.currentScenarioHasBuilt[projectDirectory]) {
if (!RNProjectManager.currentScenarioHasBuilt[projectDirectory]) {
RNProjectManager.currentScenarioHasBuilt[projectDirectory] = true;
return (<RNPlatform><any>targetPlatform).buildApp(projectDirectory);
} */
return (<RNPlatform><any>targetPlatform).buildApp(projectDirectory);
}
})
.then(() => {
// Uninstall the app so that the app's data doesn't carry over between tests.
// Uninstall the app so that the installation is clean and no files are left around for each test.
return targetPlatform.getEmulatorManager().uninstallApplication(PluginTestingFramework.TestNamespace);
})
.then(() => {
@@ -1051,9 +1054,7 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
.then<void>((updatePath: string) => {
PluginTestingFramework.updatePackagePath = updatePath;
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
return PluginTestingFramework.expectTestMessages([
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
return PluginTestingFramework.expectTestMessages([ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
})
.then<void>(() => {
targetPlatform.getEmulatorManager().restartApplication(PluginTestingFramework.TestNamespace);
@@ -1073,8 +1074,6 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
PluginTestingFramework.updatePackagePath = updatePath;
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
return PluginTestingFramework.expectTestMessages([
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
// the update is immediate so the update will install
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE,
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UP_TO_DATE])]);
})
@@ -1155,7 +1154,6 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
return PluginTestingFramework.expectTestMessages([
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
})
.then<void>(() => {
@@ -1178,8 +1176,6 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
return PluginTestingFramework.expectTestMessages([
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
// the update is immediate so the update will install
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE,
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UP_TO_DATE])]);
@@ -1299,9 +1295,7 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
.then<void>((updatePath: string) => {
PluginTestingFramework.updatePackagePath = updatePath;
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
return PluginTestingFramework.expectTestMessages([
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
return PluginTestingFramework.expectTestMessages([ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
})
.done(() => { done(); }, (e) => { done(e); });
}, false),
@@ -1341,13 +1335,11 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
.then<void>((updatePath: string) => {
PluginTestingFramework.updatePackagePath = updatePath;
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
return PluginTestingFramework.expectTestMessages([
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
return PluginTestingFramework.expectTestMessages([ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
})
.done(() => { done(); }, (e) => { done(e); });
}, false)
], undefined)
])
];
var rootTestBuilder = new PluginTestingFramework.TestBuilderDescribe("CodePush", testBuilderDescribes);