Skip to content

Commit

Permalink
solve async test messages with immediate problem
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbommarito committed Jun 1, 2016
1 parent 9905c34 commit c3e9136
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 53 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ Follow these steps to test your modifications to the plugin manually:
npm install local_path_to_your_clone_of_this_repo
```
- configure the plugin using the steps in the README.md
- build and run your app on an emulator or device

## Test

### Environment setup

First, make sure you can build the plugin by following the steps above.
First, make sure you have installed the dependencies for the plugin by following the steps above.

Then, make sure you have installed `gulp`.

Expand Down
36 changes: 30 additions & 6 deletions test/template/codePushWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
});
}
);
}
}
26 changes: 0 additions & 26 deletions test/template/ios/TestCodePush/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

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
Expand Down
32 changes: 12 additions & 20 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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);
Expand All @@ -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])]);
})
Expand Down Expand Up @@ -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>(() => {
Expand All @@ -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])]);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c3e9136

Please sign in to comment.