From c3e913632dd3f5dd2b5255be1cf6fed179985f34 Mon Sep 17 00:00:00 2001 From: scottbommarito Date: Wed, 1 Jun 2016 11:18:48 -0700 Subject: [PATCH] solve async test messages with immediate problem --- CONTRIBUTING.md | 3 +- test/template/codePushWrapper.js | 36 ++++++++++++++++---- test/template/ios/TestCodePush/AppDelegate.m | 26 -------------- test/test.ts | 32 +++++++---------- 4 files changed, 44 insertions(+), 53 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 846d49a96..8ad3c513d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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`. diff --git a/test/template/codePushWrapper.js b/test/template/codePushWrapper.js index 0317eb443..3ad1fc26e 100644 --- a/test/template/codePushWrapper.js +++ b/test/template/codePushWrapper.js @@ -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); }); + }); + } + ); } } \ No newline at end of file diff --git a/test/template/ios/TestCodePush/AppDelegate.m b/test/template/ios/TestCodePush/AppDelegate.m index 5c36069dc..9b5b9e324 100644 --- a/test/template/ios/TestCodePush/AppDelegate.m +++ b/test/template/ios/TestCodePush/AppDelegate.m @@ -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 diff --git a/test/test.ts b/test/test.ts index f6180ede7..776cd98bc 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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(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(undefined) .then(() => { // Build if this scenario has not yet been built. - /* if (!RNProjectManager.currentScenarioHasBuilt[projectDirectory]) { + if (!RNProjectManager.currentScenarioHasBuilt[projectDirectory]) { RNProjectManager.currentScenarioHasBuilt[projectDirectory] = true; return (targetPlatform).buildApp(projectDirectory); - } */ - return (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((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(() => { 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(() => { @@ -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((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((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);