From 13d933e1eb034e1b60a4e85c2c077169e38fef3f Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Wed, 23 Dec 2015 13:23:00 -0800 Subject: [PATCH 01/16] es6/es7 changes --- CodePush.js | 157 +++++++++--------- .../iOS/CodePushDemoApp/AppDelegate.m | 4 +- .../iOS/CodePushDemoApp/Info.plist | 2 +- 3 files changed, 77 insertions(+), 86 deletions(-) diff --git a/CodePush.js b/CodePush.js index 183ff65..e97c0fb 100644 --- a/CodePush.js +++ b/CodePush.js @@ -1,15 +1,13 @@ 'use strict'; -var { Alert } = require("./AlertAdapter"); -var NativeCodePush = require("react-native").NativeModules.CodePush; -var PackageMixins = require("./package-mixins")(NativeCodePush); -var requestFetchAdapter = require("./request-fetch-adapter.js"); -var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager; -var semver = require("semver"); +import { Alert } from "./AlertAdapter"; +let NativeCodePush = require("react-native").NativeModules.CodePush; +let PackageMixins = require("./package-mixins")(NativeCodePush); +import requestFetchAdapter from "./request-fetch-adapter.js"; +import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; +import semver from "semver"; -function checkForUpdate(deploymentKey = null) { - var config, sdk; - +async function checkForUpdate(deploymentKey = null) { /* * Before we ask the server if an update exists, we * need to retrieve three pieces of information from the @@ -19,81 +17,74 @@ function checkForUpdate(deploymentKey = null) { * for their specific deployment and version and which are actually * different from the CodePush update they have already installed. */ - return getConfiguration() - .then((configResult) => { - /* - * If a deployment key was explicitly provided, - * then let's override the one we retrieved - * from the native-side of the app. This allows - * dynamically "redirecting" end-users at different - * deployments (e.g. an early access deployment for insiders). - */ - if (deploymentKey) { - config = Object.assign({}, configResult, { deploymentKey }); - } else { - config = configResult; - } - - sdk = new module.exports.AcquisitionSdk(requestFetchAdapter, config); - - // Allow dynamic overwrite of function. This is only to be used for tests. - return module.exports.getCurrentPackage(); - }) - .then((localPackage) => { - var queryPackage = { appVersion: config.appVersion }; - - /* - * If the app has a previously installed update, and that update - * was targetted at the same app version that is currently running, - * then we want to use its package hash to determine whether a new - * release has been made on the server. Otherwise, we only need - * to send the app version to the server, since we are interested - * in any updates for current app store version, regardless of hash. - */ - if (localPackage && localPackage.appVersion && semver.compare(localPackage.appVersion, config.appVersion) === 0) { - queryPackage = localPackage; - } - - return new Promise((resolve, reject) => { - sdk.queryUpdateWithCurrentPackage(queryPackage, (err, update) => { - if (err) { - return reject(err); - } - - /* - * There are three cases where checkForUpdate will resolve to null: - * ---------------------------------------------------------------- - * 1) The server said there isn't an update. This is the most common case. - * 2) The server said there is an update but it requires a newer binary version. - * This would occur when end-users are running an older app store version than - * is available, and CodePush is making sure they don't get an update that - * potentially wouldn't be compatible with what they are running. - * 3) The server said there is an update, but the update's hash is the same as - * the currently running update. This should _never_ happen, unless there is a - * bug in the server, but we're adding this check just to double-check that the - * client app is resilient to a potential issue with the update check. - */ - if (!update || update.updateAppVersion || (update.packageHash === localPackage.packageHash)) { - return resolve(null); - } - - update = Object.assign(update, PackageMixins.remote); - - NativeCodePush.isFailedUpdate(update.packageHash) - .then((isFailedHash) => { - update.failedInstall = isFailedHash; - resolve(update); - }) - .catch(reject) - .done(); - }) - }); - }); + let nativeConfig = await getConfiguration(); + /* + * If a deployment key was explicitly provided, + * then let's override the one we retrieved + * from the native-side of the app. This allows + * dynamically "redirecting" end-users at different + * deployments (e.g. an early access deployment for insiders). + */ + let config = deploymentKey ? Object.assign({}, nativeConfig, { deploymentKey }) + : nativeConfig; + let sdk = getPromisifiedSdk(requestFetchAdapter, config); + // Use dynamically overridden getCurrentPackage() during tests. + let localPackage = await module.exports.getCurrentPackage(); + /* + * If the app has a previously installed update, and that update + * was targetted at the same app version that is currently running, + * then we want to use its package hash to determine whether a new + * release has been made on the server. Otherwise, we only need + * to send the app version to the server, since we are interested + * in any updates for current app store version, regardless of hash. + */ + let queryPackage = localPackage && localPackage.appVersion && semver.compare(localPackage.appVersion, config.appVersion) === 0 + ? localPackage + : { appVersion: config.appVersion }; + let update = await sdk.queryUpdateWithCurrentPackage(queryPackage); + /* + * There are three cases where checkForUpdate will resolve to null: + * ---------------------------------------------------------------- + * 1) The server said there isn't an update. This is the most common case. + * 2) The server said there is an update but it requires a newer binary version. + * This would occur when end-users are running an older app store version than + * is available, and CodePush is making sure they don't get an update that + * potentially wouldn't be compatible with what they are running. + * 3) The server said there is an update, but the update's hash is the same as + * the currently running update. This should _never_ happen, unless there is a + * bug in the server, but we're adding this check just to double-check that the + * client app is resilient to a potential issue with the update check. + */ + if (!update || update.updateAppVersion || (update.packageHash === localPackage.packageHash)) { + return null; + } else { + let remotePackage = Object.assign(update, PackageMixins.remote); + remotePackage.failedInstall = await NativeCodePush.isFailedUpdate(remotePackage.packageHash); + return remotePackage; + } } -var getConfiguration = (() => { - var config; - return function getConfiguration() { +function getPromisifiedSdk(requestFetchAdapter, config) { + // Use dynamically overridden AcquisitionSdk during tests. + let sdk = new module.exports.AcquisitionSdk(requestFetchAdapter, config); + sdk.queryUpdateWithCurrentPackage = (queryPackage) => { + return new Promise((resolve, reject) => { + sdk.queryUpdateWithCurrentPackage(queryPackage, (err, update) => { + if (err) { + reject(err); + } else { + resolve(update); + } + }); + }); + }; + + return sdk; +} + +let getConfiguration = (() => { + let config; + return () => { if (config) { return Promise.resolve(config); } else if (testConfig) { @@ -105,7 +96,7 @@ var getConfiguration = (() => { return config; }); } - } + }; })(); function getCurrentPackage() { diff --git a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/AppDelegate.m b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/AppDelegate.m index aac98cc..11de946 100644 --- a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/AppDelegate.m +++ b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/AppDelegate.m @@ -33,7 +33,7 @@ * on the same Wi-Fi network. */ - //jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.includeRequire.runModule.bundle?dev=true&platform=ios"]; + jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.includeRequire.runModule.bundle?dev=true&platform=ios"]; /** * OPTION 2 @@ -45,7 +45,7 @@ * see http://facebook.github.io/react-native/docs/runningondevice.html */ - jsCodeLocation = [CodePush bundleURL]; + //jsCodeLocation = [CodePush bundleURL]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"CodePushDemoApp" diff --git a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist index e1033b9..6cb683d 100644 --- a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist +++ b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist @@ -44,6 +44,6 @@ NSLocationWhenInUseUsageDescription CodePushDeploymentKey - deployment-key-here + 5c73310a-cc93-4aa5-bf9f-81c6b648232c From aac19e25d6875c6726d8aec42ecbd64ed219e684 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Wed, 23 Dec 2015 17:19:24 -0800 Subject: [PATCH 02/16] more changes --- CodePush.js | 59 +++++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/CodePush.js b/CodePush.js index e97c0fb..bae587a 100644 --- a/CodePush.js +++ b/CodePush.js @@ -64,6 +64,27 @@ async function checkForUpdate(deploymentKey = null) { } } +let getConfiguration = (() => { + let config; + return async function getConfiguration() { + if (config) { + return config; + } else if (testConfig) { + return testConfig; + } else { + config = await NativeCodePush.getConfiguration(); + return config; + } + } +})(); + +async function getCurrentPackage() { + let localPackage = await NativeCodePush.getCurrentPackage(); + localPackage.failedInstall = await NativeCodePush.isFailedUpdate(localPackage.packageHash); + localPackage.isFirstRun = await NativeCodePush.isFirstRun(localPackage.packageHash); + return localPackage; +} + function getPromisifiedSdk(requestFetchAdapter, config) { // Use dynamically overridden AcquisitionSdk during tests. let sdk = new module.exports.AcquisitionSdk(requestFetchAdapter, config); @@ -82,44 +103,6 @@ function getPromisifiedSdk(requestFetchAdapter, config) { return sdk; } -let getConfiguration = (() => { - let config; - return () => { - if (config) { - return Promise.resolve(config); - } else if (testConfig) { - return Promise.resolve(testConfig); - } else { - return NativeCodePush.getConfiguration() - .then((configuration) => { - if (!config) config = configuration; - return config; - }); - } - }; -})(); - -function getCurrentPackage() { - return new Promise((resolve, reject) => { - var localPackage; - NativeCodePush.getCurrentPackage() - .then((currentPackage) => { - localPackage = currentPackage; - return NativeCodePush.isFailedUpdate(currentPackage.packageHash); - }) - .then((failedUpdate) => { - localPackage.failedInstall = failedUpdate; - return NativeCodePush.isFirstRun(localPackage.packageHash); - }) - .then((isFirstRun) => { - localPackage.isFirstRun = isFirstRun; - resolve(localPackage); - }) - .catch(reject) - .done(); - }); -} - /* Logs messages to console with the [CodePush] prefix */ function log(message) { console.log(`[CodePush] ${message}`) From ebd93b53ebb6c5c1f698865c015f0b32af81eb24 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Wed, 23 Dec 2015 21:24:29 -0800 Subject: [PATCH 03/16] es7 --- CodePush.js | 158 ++++++++---------- .../CheckForUpdateTestApp.js | 1 + .../testcases/FirstUpdateTest.js | 19 +-- .../testcases/NewUpdateTest.js | 21 +-- .../testcases/NoRemotePackageTest.js | 19 +-- .../RemotePackageAppVersionNewerTest.js | 27 ++- .../testcases/SamePackageTest.js | 19 +-- .../testcases/SwitchDeploymentKeyTest.js | 21 +-- .../testcases/DownloadProgressTest.js | 2 +- .../resources/CheckIsFirstRunAndPassTest.js | 25 ++- .../resources/IsFailedUpdateTestBundleV1.js | 39 ++--- .../resources/IsFailedUpdateTestBundleV2.js | 1 + .../NotifyApplicationReadyAndRestart.js | 21 +-- .../resources/RollbackTestBundleV1.js | 47 ++---- .../testcases/InstallModeImmediateTest.js | 9 +- .../testcases/InstallModeOnNextRestartTest.js | 13 +- .../testcases/InstallModeOnNextResumeTest.js | 13 +- .../testcases/IsFailedUpdateTest.js | 9 +- .../testcases/IsFirstRunTest.js | 9 +- .../testcases/IsPendingTest.js | 19 +-- .../testcases/NotifyApplicationReadyTest.js | 9 +- .../testcases/RollbackTest.js | 9 +- .../utils/createTestCaseComponent.js | 23 ++- Examples/CodePushDemoApp/crossplatformdemo.js | 144 ++++++++-------- .../iOS/CodePushDemoApp/AppDelegate.m | 4 +- .../iOS/CodePushDemoApp/Info.plist | 2 +- Examples/CodePushDemoApp/index.android.js | 2 +- Examples/CodePushDemoApp/index.ios.js | 2 +- package-mixins.js | 47 +++--- 29 files changed, 309 insertions(+), 425 deletions(-) diff --git a/CodePush.js b/CodePush.js index bae587a..a688669 100644 --- a/CodePush.js +++ b/CodePush.js @@ -90,7 +90,7 @@ function getPromisifiedSdk(requestFetchAdapter, config) { let sdk = new module.exports.AcquisitionSdk(requestFetchAdapter, config); sdk.queryUpdateWithCurrentPackage = (queryPackage) => { return new Promise((resolve, reject) => { - sdk.queryUpdateWithCurrentPackage(queryPackage, (err, update) => { + module.exports.AcquisitionSdk.prototype.queryUpdateWithCurrentPackage.call(sdk, queryPackage, (err, update) => { if (err) { reject(err); } else { @@ -126,8 +126,8 @@ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) { * releases, and displaying a standard confirmation UI to the end-user * when an update is available. */ -function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback) { - var syncOptions = { +async function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback) { + let syncOptions = { deploymentKey: null, ignoreFailedUpdates: true, @@ -139,7 +139,7 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback) syncStatusChangeCallback = typeof syncStatusChangeCallback == "function" ? syncStatusChangeCallback - : function(syncStatus) { + : (syncStatus) => { switch(syncStatus) { case CodePush.SyncStatus.CHECKING_FOR_UPDATE: log("Checking for update."); @@ -178,93 +178,83 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback) downloadProgressCallback = typeof downloadProgressCallback == "function" ? downloadProgressCallback - : function(downloadProgress) { + : (downloadProgress) => { log(`Expecting ${downloadProgress.totalBytes} bytes, received ${downloadProgress.receivedBytes} bytes.`); }; - return new Promise((resolve, reject) => { - var rejectPromise = (error) => { - syncStatusChangeCallback(CodePush.SyncStatus.UNKNOWN_ERROR); - log(error.message); - reject(error); + try { + await CodePush.notifyApplicationReady(); + + syncStatusChangeCallback(CodePush.SyncStatus.CHECKING_FOR_UPDATE); + let remotePackage = await checkForUpdate(syncOptions.deploymentKey); + + let doDownloadAndInstall = async () => { + syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE); + let localPackage = await remotePackage.download(downloadProgressCallback); + + syncStatusChangeCallback(CodePush.SyncStatus.INSTALLING_UPDATE); + await localPackage.install(syncOptions.installMode, () => { + syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED); + }); + + return CodePush.SyncStatus.UPDATE_INSTALLED; }; - CodePush.notifyApplicationReady() - .then(() => { - syncStatusChangeCallback(CodePush.SyncStatus.CHECKING_FOR_UPDATE); - return checkForUpdate(syncOptions.deploymentKey); - }) - .then((remotePackage) => { - var doDownloadAndInstall = () => { - syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE); - remotePackage.download(downloadProgressCallback) - .then((localPackage) => { - syncStatusChangeCallback(CodePush.SyncStatus.INSTALLING_UPDATE); - return localPackage.install(syncOptions.installMode, () => { - syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED); - resolve(CodePush.SyncStatus.UPDATE_INSTALLED); - }); - }) - .catch(rejectPromise) - .done(); + if (!remotePackage || (remotePackage.failedInstall && syncOptions.ignoreFailedUpdates)) { + syncStatusChangeCallback(CodePush.SyncStatus.UP_TO_DATE); + return (CodePush.SyncStatus.UP_TO_DATE); + } else if (syncOptions.updateDialog) { + // updateDialog supports any truthy value (e.g. true, "goo", 12), + // but we should treat a non-object value as just the default dialog + if (typeof syncOptions.updateDialog !== "object") { + syncOptions.updateDialog = CodePush.DEFAULT_UPDATE_DIALOG; + } else { + syncOptions.updateDialog = Object.assign({}, CodePush.DEFAULT_UPDATE_DIALOG, syncOptions.updateDialog); + } + + return await new Promise((resolve, reject) => { + let message = null; + let dialogButtons = [{ + text: null, + onPress: async () => { + resolve(await doDownloadAndInstall()); + } + }]; + + if (remotePackage.isMandatory) { + message = syncOptions.updateDialog.mandatoryUpdateMessage; + dialogButtons[0].text = syncOptions.updateDialog.mandatoryContinueButtonLabel; + } else { + message = syncOptions.updateDialog.optionalUpdateMessage; + dialogButtons[0].text = syncOptions.updateDialog.optionalInstallButtonLabel; + // Since this is an optional update, add another button + // to allow the end-user to ignore it + dialogButtons.push({ + text: syncOptions.updateDialog.optionalIgnoreButtonLabel, + onPress: () => { + syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_IGNORED); + resolve(CodePush.SyncStatus.UPDATE_IGNORED); + } + }); } - if (!remotePackage || (remotePackage.failedInstall && syncOptions.ignoreFailedUpdates)) { - syncStatusChangeCallback(CodePush.SyncStatus.UP_TO_DATE); - resolve(CodePush.SyncStatus.UP_TO_DATE); + // If the update has a description, and the developer + // explicitly chose to display it, then set that as the message + if (syncOptions.updateDialog.appendReleaseDescription && remotePackage.description) { + message += `${syncOptions.updateDialog.descriptionPrefix} ${remotePackage.description}`; } - else if (syncOptions.updateDialog) { - // updateDialog supports any truthy value (e.g. true, "goo", 12), - // but we should treat a non-object value as just the default dialog - if (typeof syncOptions.updateDialog !== "object") { - syncOptions.updateDialog = CodePush.DEFAULT_UPDATE_DIALOG; - } else { - syncOptions.updateDialog = Object.assign({}, CodePush.DEFAULT_UPDATE_DIALOG, syncOptions.updateDialog); - } - - var message = null; - var dialogButtons = [ - { - text: null, - onPress: () => { - doDownloadAndInstall(); - } - } - ]; - - if (remotePackage.isMandatory) { - message = syncOptions.updateDialog.mandatoryUpdateMessage; - dialogButtons[0].text = syncOptions.updateDialog.mandatoryContinueButtonLabel; - } else { - message = syncOptions.updateDialog.optionalUpdateMessage; - dialogButtons[0].text = syncOptions.updateDialog.optionalInstallButtonLabel; - - // Since this is an optional update, add another button - // to allow the end-user to ignore it - dialogButtons.push({ - text: syncOptions.updateDialog.optionalIgnoreButtonLabel, - onPress: () => { - syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_IGNORED); - resolve(CodePush.SyncStatus.UPDATE_IGNORED); - } - }); - } - - // If the update has a description, and the developer - // explicitly chose to display it, then set that as the message - if (syncOptions.updateDialog.appendReleaseDescription && remotePackage.description) { - message += `${syncOptions.updateDialog.descriptionPrefix} ${remotePackage.description}`; - } - - syncStatusChangeCallback(CodePush.SyncStatus.AWAITING_USER_ACTION); - Alert.alert(syncOptions.updateDialog.title, message, dialogButtons); - } else { - doDownloadAndInstall(); - } - }) - .catch(rejectPromise) - .done(); - }); + + syncStatusChangeCallback(CodePush.SyncStatus.AWAITING_USER_ACTION); + Alert.alert(syncOptions.updateDialog.title, message, dialogButtons); + }); + } else { + return await doDownloadAndInstall(); + } + } catch (error) { + syncStatusChangeCallback(CodePush.SyncStatus.UNKNOWN_ERROR); + log(error.message); + throw error; + } }; var CodePush = { @@ -304,4 +294,4 @@ var CodePush = { } }; -module.exports = CodePush; +export default CodePush; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp.js index 62393c2..22250cc 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp.js @@ -38,6 +38,7 @@ let CheckForUpdateTestApp = React.createClass({ ); } + return ( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js index 33b286b..bf27f6a 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js @@ -18,20 +18,13 @@ let FirstUpdateTest = createTestCaseComponent( let mockAcquisitionSdk = createMockAcquisitionSdk(serverPackage, localPackage); let mockConfiguration = { appVersion : "1.5.0" }; CodePush.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeCodePush); - CodePush.getCurrentPackage = () => { - return Promise.resolve(localPackage); - } - return Promise.resolve(); + CodePush.getCurrentPackage = async () => { + return localPackage; + }; }, - () => { - return CodePush.checkForUpdate() - .then((update) => { - if (update) { - assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote)); - } else { - throw new Error("checkForUpdate did not return the update from the server"); - } - }); + async () => { + let update = await CodePush.checkForUpdate() + assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote), "checkForUpdate did not return the update from the server"); } ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js index f020fce..393fdd2 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js @@ -17,21 +17,14 @@ let NewUpdateTest = createTestCaseComponent( let mockAcquisitionSdk = createMockAcquisitionSdk(serverPackage, localPackage); let mockConfiguration = { appVersion : "1.5.0" }; CodePush.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeCodePush); - CodePush.getCurrentPackage = () => { - return Promise.resolve(localPackage); - } - return Promise.resolve(); + CodePush.getCurrentPackage = async () => { + return localPackage; + }; }, - () => { - return CodePush.checkForUpdate() - .then((update) => { - if (update) { - assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote)); - } else { - throw new Error("checkForUpdate did not return the update from the server"); - } - }); + async () => { + let update = await CodePush.checkForUpdate() + assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote), "checkForUpdate did not return the update from the server"); } ); -module.exports = NewUpdateTest; \ No newline at end of file +export default NewUpdateTest; \ No newline at end of file diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js index d3fb582..5464e7a 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js @@ -18,19 +18,14 @@ let NoRemotePackageTest = createTestCaseComponent( let mockAcquisitionSdk = createMockAcquisitionSdk(serverPackage, localPackage); let mockConfiguration = { appVersion : "1.5.0" }; CodePush.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeCodePush); - CodePush.getCurrentPackage = () => { - return Promise.resolve(localPackage); - } - return Promise.resolve(); + CodePush.getCurrentPackage = async () => { + return localPackage; + }; }, - () => { - return CodePush.checkForUpdate() - .then((update) => { - if (update) { - throw new Error("checkForUpdate should not return an update if there is none on the server"); - } - }); + async () => { + let update = await CodePush.checkForUpdate(); + assert(!update, "checkForUpdate should not return an update if there is none on the server"); } ); -module.exports = NoRemotePackageTest; \ No newline at end of file +export default NoRemotePackageTest; \ No newline at end of file diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js index 4b4af51..50f9d57 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js @@ -15,24 +15,17 @@ let RemotePackageAppVersionNewerTest = createTestCaseComponent( "RemotePackageAppVersionNewerTest", "should drop the update when the server reports one with a newer binary version", () => { - return new Promise((resolve, reject) => { - let mockAcquisitionSdk = createMockAcquisitionSdk(serverPackage, localPackage); - let mockConfiguration = { appVersion : "1.0.0" }; - CodePush.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeCodePush); - CodePush.getCurrentPackage = () => { - return Promise.resolve(localPackage); - } - resolve(); - }); + let mockAcquisitionSdk = createMockAcquisitionSdk(serverPackage, localPackage); + let mockConfiguration = { appVersion : "1.0.0" }; + CodePush.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeCodePush); + CodePush.getCurrentPackage = async () => { + return localPackage; + }; }, - () => { - return CodePush.checkForUpdate() - .then((update) => { - if (update) { - throw new Error("checkForUpdate should not return an update if remote package is of a different binary version"); - } - }); + async () => { + let update = await CodePush.checkForUpdate() + assert(!update, "checkForUpdate should not return an update if remote package is of a different binary version"); } ); -module.exports = RemotePackageAppVersionNewerTest; \ No newline at end of file +export default RemotePackageAppVersionNewerTest; \ No newline at end of file diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js index 88288c8..ba401f7 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js @@ -18,19 +18,14 @@ let SamePackageTest = createTestCaseComponent( let mockAcquisitionSdk = createMockAcquisitionSdk(serverPackage, localPackage); let mockConfiguration = { appVersion : "1.5.0" }; CodePush.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeCodePush); - CodePush.getCurrentPackage = () => { - return Promise.resolve(localPackage); - } - return Promise.resolve(); + CodePush.getCurrentPackage = async () => { + return localPackage; + }; }, - () => { - return CodePush.checkForUpdate() - .then((update) => { - if (update) { - throw new Error("checkForUpdate should not return a package when local package is identical"); - } - }); + async () => { + let update = await CodePush.checkForUpdate(); + assert(!update, "checkForUpdate should not return a package when local package is identical"); } ); -module.exports = SamePackageTest; \ No newline at end of file +export default SamePackageTest; \ No newline at end of file diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js index 4205559..caceded 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js @@ -20,21 +20,14 @@ let SwitchDeploymentKeyTest = createTestCaseComponent( let mockAcquisitionSdk = createMockAcquisitionSdk(serverPackage, localPackage, deploymentKey); let mockConfiguration = { appVersion : "1.5.0" }; CodePush.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeCodePush); - CodePush.getCurrentPackage = () => { - return Promise.resolve(localPackage); - } - return Promise.resolve(); + CodePush.getCurrentPackage = async () => { + return localPackage; + }; }, - () => { - return CodePush.checkForUpdate(deploymentKey) - .then((update) => { - if (update) { - assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote)); - } else { - throw new Error("checkForUpdate did not return the update from the server"); - } - }); + async () => { + let update = await CodePush.checkForUpdate(deploymentKey) + assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote), "checkForUpdate did not return the update from the server"); } ); -module.exports = SwitchDeploymentKeyTest; \ No newline at end of file +export default SwitchDeploymentKeyTest; \ No newline at end of file diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js index b54f3e5..7841f66 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js @@ -49,4 +49,4 @@ let DownloadProgressTest = createTestCaseComponent( } ); -module.exports = DownloadProgressTest; \ No newline at end of file +export default DownloadProgressTest; \ No newline at end of file diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/CheckIsFirstRunAndPassTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/CheckIsFirstRunAndPassTest.js index 52ddf35..54e2ad5 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/CheckIsFirstRunAndPassTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/CheckIsFirstRunAndPassTest.js @@ -1,27 +1,24 @@ "use strict"; -import React from "react-native"; -import CodePush from "react-native-code-push"; - -let { +import React, { AppRegistry, Text, View, -} = React; +} from "react-native"; + +import CodePush from "react-native-code-push"; let IsFirstRunTest = React.createClass({ getInitialState() { return {}; }, - componentDidMount() { - CodePush.getCurrentPackage() - .then((localPackage) => { - if (localPackage.isFirstRun) { - this.setState({ passed: true }); - } else { - this.setState({ passed: false }); - } - }); + async componentDidMount() { + let localPackage = await CodePush.getCurrentPackage(); + if (localPackage.isFirstRun) { + this.setState({ passed: true }); + } else { + this.setState({ passed: false }); + } }, render() { let text = "Testing..."; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js index d7f2eb2..72ee0dc 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js @@ -1,23 +1,22 @@ "use strict"; -import React from "react-native"; +import React, { + AppRegistry, + Platform, + Text, + View, +} from "react-native"; + import CodePush from "react-native-code-push"; let NativeCodePush = React.NativeModules.CodePush; let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; -let { - AppRegistry, - Platform, - Text, - View, -} = React; - let IsFailedUpdateTest = React.createClass({ getInitialState() { return {}; }, - componentDidMount() { + async componentDidMount() { let serverPackage = { description: "Angry flappy birds", appVersion: "1.5.0", @@ -39,20 +38,14 @@ let IsFailedUpdateTest = React.createClass({ let mockConfiguration = { appVersion : "1.5.0" }; CodePush.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeCodePush); - CodePush.notifyApplicationReady() - .then(() => { - return CodePush.checkForUpdate(); - }) - .then((remotePackage) => { - if (remotePackage.failedInstall) { - this.setState({ passed: true }); - } else { - return remotePackage.download(); - } - }) - .then((localPackage) => { - return localPackage && localPackage.install(NativeCodePush.codePushInstallModeImmediate); - }); + await CodePush.notifyApplicationReady() + let remotePackage = await CodePush.checkForUpdate(); + if (remotePackage.failedInstall) { + this.setState({ passed: true }); + } else { + let localPackage = await remotePackage.download(); + return localPackage && await localPackage.install(NativeCodePush.codePushInstallModeImmediate); + } }, render() { let text = "Testing..."; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV2.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV2.js index bd8fc8a..da8f2f4 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV2.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV2.js @@ -11,6 +11,7 @@ let { let IsFailedUpdateTest = React.createClass({ componentDidMount() { + // Should trigger a rollback. CodePush.restartApp(); }, render() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js index fcd9f2d..338e2ae 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js @@ -10,18 +10,15 @@ let NotifyApplicationReadyTest = React.createClass({ getInitialState() { return {}; }, - componentDidMount() { - CodePush.notifyApplicationReady() - .then(() => { - if (Platform.OS === "android") { - return NativeCodePush.downloadAndReplaceCurrentBundle("http://10.0.3.2:8081/CodePushDemoAppTests/InstallUpdateTests/resources/PassNotifyApplicationReadyTest.includeRequire.runModule.bundle?platform=android&dev=true"); - } else if (Platform.OS === "ios") { - return NativeCodePush.downloadAndReplaceCurrentBundle("http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/resources/PassNotifyApplicationReadyTest.includeRequire.runModule.bundle?platform=ios&dev=true"); - } - }) - .then(() => { - CodePush.restartApp(); - }); + async componentDidMount() { + await CodePush.notifyApplicationReady(); + if (Platform.OS === "android") { + await NativeCodePush.downloadAndReplaceCurrentBundle("http://10.0.3.2:8081/CodePushDemoAppTests/InstallUpdateTests/resources/PassNotifyApplicationReadyTest.includeRequire.runModule.bundle?platform=android&dev=true"); + } else if (Platform.OS === "ios") { + await NativeCodePush.downloadAndReplaceCurrentBundle("http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/resources/PassNotifyApplicationReadyTest.includeRequire.runModule.bundle?platform=ios&dev=true"); + } + + CodePush.restartApp(); }, render() { return ( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js index 12eb9c5..1877c84 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js @@ -1,51 +1,36 @@ "use strict"; -import React from "react-native"; +import React, { + AppRegistry, + Platform, + Text, + View, +} from "react-native"; + import CodePush from "react-native-code-push"; let RCTTestModule = React.NativeModules.TestModule; let NativeCodePush = React.NativeModules.CodePush; let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); -let { - AppRegistry, - Platform, - Text, - View, -} = React; - let RollbackTest = React.createClass({ - componentDidMount() { - let remotePackage = { - description: "Angry flappy birds", - appVersion: "1.5.0", - label: "2.4.0", - isMandatory: false, - isAvailable: true, - updateAppVersion: false, - packageHash: "hash241", - packageSize: 1024 - }; + async componentDidMount() { + let remotePackage = require("./remotePackage"); + remotePackage.packageHash = "hash241"; if (Platform.OS === "android") { remotePackage.downloadUrl = "http://10.0.3.2:8081/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV2.includeRequire.runModule.bundle?platform=android&dev=true" - CodePush.notifyApplicationReady() - .then(() => { - NativeCodePush.downloadAndReplaceCurrentBundle("http://10.0.3.2:8081/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.includeRequire.runModule.bundle?platform=android&dev=true"); - }); + await CodePush.notifyApplicationReady(); + await NativeCodePush.downloadAndReplaceCurrentBundle("http://10.0.3.2:8081/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.includeRequire.runModule.bundle?platform=android&dev=true"); } else if (Platform.OS === "ios") { remotePackage.downloadUrl = "http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV2.includeRequire.runModule.bundle?platform=ios&dev=true" - CodePush.notifyApplicationReady() - .then(() => { - NativeCodePush.downloadAndReplaceCurrentBundle("http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.includeRequire.runModule.bundle?platform=ios&dev=true"); - }); + await CodePush.notifyApplicationReady() + await NativeCodePush.downloadAndReplaceCurrentBundle("http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.includeRequire.runModule.bundle?platform=ios&dev=true"); } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeImmediate); - }); + let localPackage = await remotePackage.download(); + return await localPackage.install(NativeCodePush.codePushInstallModeImmediate); }, render() { return ( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js index aa83023..640b0fe 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js @@ -21,13 +21,10 @@ let InstallModeImmediateTest = createTestCaseComponent( } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - return Promise.resolve(); }, - () => { - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeImmediate); - }); + async () => { + let localPackage = await remotePackage.download(); + return await localPackage.install(NativeCodePush.codePushInstallModeImmediate); }, /*passAfterRun*/ false ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js index 6429de8..5fa78fa 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js @@ -22,16 +22,11 @@ let InstallModeOnNextRestartTest = createTestCaseComponent( } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - return Promise.resolve(); }, - () => { - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeOnNextRestart); - }) - .then(() => { - CodePush.restartApp(); - }); + async () => { + let localPackage = await remotePackage.download(); + await localPackage.install(NativeCodePush.codePushInstallModeOnNextRestart); + CodePush.restartApp(); }, /*passAfterRun*/ false ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js index 942d17e..8596d61 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js @@ -21,16 +21,11 @@ let InstallModeOnNextResumeTest = createTestCaseComponent( } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - return Promise.resolve(); }, - () => { - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeOnNextResume); - }) - .then(() => { - CodePush.restartApp(); - }); + async () => { + let localPackage = await remotePackage.download() + await localPackage.install(NativeCodePush.codePushInstallModeOnNextResume); + CodePush.restartApp(); }, /*passAfterRun*/ false ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js index 78c4c6a..59a787f 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js @@ -21,13 +21,10 @@ let IsFailedUpdateTest = createTestCaseComponent( } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - return Promise.resolve(); }, - () => { - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeImmediate); - }); + async () => { + let localPackage = await remotePackage.download(); + return await localPackage.install(NativeCodePush.codePushInstallModeImmediate); }, /*passAfterRun*/ false ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js index 0c0866b..d31f910 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js @@ -21,13 +21,10 @@ let IsFirstRunTest = createTestCaseComponent( } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - return Promise.resolve(); }, - () => { - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeImmediate); - }); + async () => { + let localPackage = await remotePackage.download(); + return await localPackage.install(NativeCodePush.codePushInstallModeImmediate); }, /*passAfterRun*/ false ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js index 901ef12..bd6825a 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js @@ -21,20 +21,13 @@ let IsPendingTest = createTestCaseComponent( } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - return Promise.resolve(); }, - () => { - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeOnNextRestart); - }) - .then((localPackage) => { - assert(localPackage.isPending, "isPending should be set to \"true\" after an install"); - return CodePush.getCurrentPackage(); - }) - .then((localPackage) => { - assert(localPackage.isPending, "isPending should be set to \"true\" after an install"); - }); + async () => { + let localPackage = await remotePackage.download(); + await localPackage.install(NativeCodePush.codePushInstallModeOnNextRestart); + assert(localPackage.isPending, "isPending should be set to \"true\" after an install"); + localPackage = await CodePush.getCurrentPackage(); + assert(localPackage.isPending, "isPending should be set to \"true\" after an install"); } ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js index a38fcf2..df233f1 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js @@ -21,13 +21,10 @@ let NotifyApplicationReadyTest = createTestCaseComponent( } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - return Promise.resolve(); }, - () => { - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeImmediate); - }); + async () => { + let localPackage = await remotePackage.download() + return await localPackage.install(NativeCodePush.codePushInstallModeImmediate); }, /*passAfterRun*/ false ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js index 3c098ba..6d4cd3e 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js @@ -21,13 +21,10 @@ let RollbackTest = createTestCaseComponent( } remotePackage = Object.assign(remotePackage, PackageMixins.remote); - return Promise.resolve(); }, - () => { - remotePackage.download() - .then((localPackage) => { - return localPackage.install(NativeCodePush.codePushInstallModeImmediate); - }); + async () => { + let localPackage = await remotePackage.download() + return await localPackage.install(NativeCodePush.codePushInstallModeImmediate); }, /*passAfterRun*/ false ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js index 22d300c..9af45e3 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js @@ -18,18 +18,17 @@ function createTestCaseComponent(displayName, description, setUp, runTest, passA done: false, }; }, - componentDidMount() { - setUp() - .then(runTest) - .then(() => { - if (passAfterRun) { - this.setState({done: true}, RCTTestModule.markTestCompleted); - } - }) - .catch((err) => { - console.error(err); - throw err; - }); + async componentDidMount() { + try { + await setUp(); + await runTest(); + if (passAfterRun) { + this.setState({done: true}, RCTTestModule.markTestCompleted); + } + } catch (err) { + console.error(err); + throw err; + } }, render() { return ( diff --git a/Examples/CodePushDemoApp/crossplatformdemo.js b/Examples/CodePushDemoApp/crossplatformdemo.js index b05a128..b340b3f 100644 --- a/Examples/CodePushDemoApp/crossplatformdemo.js +++ b/Examples/CodePushDemoApp/crossplatformdemo.js @@ -1,7 +1,6 @@ 'use strict'; -var React = require('react-native'); -var { +import React, { AppRegistry, Dimensions, Image, @@ -9,84 +8,85 @@ var { Text, TouchableOpacity, View, -} = React; +} from "react-native"; -var Button = require("react-native-button"); +import Button from "react-native-button"; +import CodePush from "react-native-code-push"; -var CodePush = require('react-native-code-push'); - -var CodePushDemoApp = React.createClass({ - sync() { - var self = this; - CodePush.sync( - { - updateDialog: true, - installMode: CodePush.InstallMode.ON_NEXT_RESUME - }, - function(syncStatus) { - switch(syncStatus) { - case CodePush.SyncStatus.CHECKING_FOR_UPDATE: - self.setState({ - syncMessage: "Checking for update." - }); - break; - case CodePush.SyncStatus.DOWNLOADING_PACKAGE: - self.setState({ - syncMessage: "Downloading package." - }); - break; - case CodePush.SyncStatus.AWAITING_USER_ACTION: - self.setState({ - syncMessage: "Awaiting user action." - }); - break; - case CodePush.SyncStatus.INSTALLING_UPDATE: - self.setState({ - syncMessage: "Installing update." - }); - break; - case CodePush.SyncStatus.UP_TO_DATE: - self.setState({ - syncMessage: "App up to date.", - progress: false - }); - break; - case CodePush.SyncStatus.UPDATE_IGNORED: - self.setState({ - syncMessage: "Update cancelled by user.", - progress: false - }); - break; - case CodePush.SyncStatus.UPDATE_INSTALLED: - self.setState({ - syncMessage: "Update installed and will be run when the app next resumes.", - progress: false - }); - break; - case CodePush.SyncStatus.UNKNOWN_ERROR: - self.setState({ - syncMessage: "An unknown error occurred.", - progress: false - }); - break; +let CodePushDemoApp = React.createClass({ + async sync() { + let self = this; + try { + return await CodePush.sync( + { + updateDialog: true, + installMode: CodePush.InstallMode.ON_NEXT_RESUME + }, + (syncStatus) => { + switch(syncStatus) { + case CodePush.SyncStatus.CHECKING_FOR_UPDATE: + self.setState({ + syncMessage: "Checking for update." + }); + break; + case CodePush.SyncStatus.DOWNLOADING_PACKAGE: + self.setState({ + syncMessage: "Downloading package." + }); + break; + case CodePush.SyncStatus.AWAITING_USER_ACTION: + self.setState({ + syncMessage: "Awaiting user action." + }); + break; + case CodePush.SyncStatus.INSTALLING_UPDATE: + self.setState({ + syncMessage: "Installing update." + }); + break; + case CodePush.SyncStatus.UP_TO_DATE: + self.setState({ + syncMessage: "App up to date.", + progress: false + }); + break; + case CodePush.SyncStatus.UPDATE_IGNORED: + self.setState({ + syncMessage: "Update cancelled by user.", + progress: false + }); + break; + case CodePush.SyncStatus.UPDATE_INSTALLED: + self.setState({ + syncMessage: "Update installed and will be run when the app next resumes.", + progress: false + }); + break; + case CodePush.SyncStatus.UNKNOWN_ERROR: + self.setState({ + syncMessage: "An unknown error occurred.", + progress: false + }); + break; + } + }, + (progress) => { + self.setState({ + progress: progress + }); } - }, - function(progress) { - self.setState({ - progress: progress - }); - } - ).catch(function(error) { + ); + } catch (error) { CodePush.log(error); - }); + } }, + getInitialState() { return { }; }, + render() { - var syncView; - var syncButton; - var progressView; + let syncView, syncButton, progressView; if (this.state.syncMessage) { syncView = ( @@ -120,7 +120,7 @@ var CodePushDemoApp = React.createClass({ } }); -var styles = StyleSheet.create({ +let styles = StyleSheet.create({ image: { marginTop: 50, width: Dimensions.get('window').width - 100, diff --git a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/AppDelegate.m b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/AppDelegate.m index 11de946..aac98cc 100644 --- a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/AppDelegate.m +++ b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/AppDelegate.m @@ -33,7 +33,7 @@ * on the same Wi-Fi network. */ - jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.includeRequire.runModule.bundle?dev=true&platform=ios"]; + //jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.includeRequire.runModule.bundle?dev=true&platform=ios"]; /** * OPTION 2 @@ -45,7 +45,7 @@ * see http://facebook.github.io/react-native/docs/runningondevice.html */ - //jsCodeLocation = [CodePush bundleURL]; + jsCodeLocation = [CodePush bundleURL]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"CodePushDemoApp" diff --git a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist index 6cb683d..e1033b9 100644 --- a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist +++ b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist @@ -44,6 +44,6 @@ NSLocationWhenInUseUsageDescription CodePushDeploymentKey - 5c73310a-cc93-4aa5-bf9f-81c6b648232c + deployment-key-here diff --git a/Examples/CodePushDemoApp/index.android.js b/Examples/CodePushDemoApp/index.android.js index f682949..d946285 100644 --- a/Examples/CodePushDemoApp/index.android.js +++ b/Examples/CodePushDemoApp/index.android.js @@ -1 +1 @@ -require("./crossplatformdemo.js"); \ No newline at end of file +import "./crossplatformdemo.js"; \ No newline at end of file diff --git a/Examples/CodePushDemoApp/index.ios.js b/Examples/CodePushDemoApp/index.ios.js index f682949..d946285 100644 --- a/Examples/CodePushDemoApp/index.ios.js +++ b/Examples/CodePushDemoApp/index.ios.js @@ -1 +1 @@ -require("./crossplatformdemo.js"); \ No newline at end of file +import "./crossplatformdemo.js"; \ No newline at end of file diff --git a/package-mixins.js b/package-mixins.js index d539ab9..a74ee11 100644 --- a/package-mixins.js +++ b/package-mixins.js @@ -3,18 +3,14 @@ import { DeviceEventEmitter } from "react-native"; // This function is used to augment remote and local // package objects with additional functionality/properties // beyond what is included in the metadata sent by the server. -module.exports = (NativeCodePush) => { +export default (NativeCodePush) => { const remote = { - abortDownload() { - return NativeCodePush.abortDownload(this); - }, - - download(downloadProgressCallback) { + async download(downloadProgressCallback) { if (!this.downloadUrl) { - return Promise.reject(new Error("Cannot download an update without a download url")); + throw new Error("Cannot download an update without a download url"); } - var downloadProgressSubscription; + let downloadProgressSubscription; if (downloadProgressCallback) { // Use event subscription to obtain download progress. downloadProgressSubscription = DeviceEventEmitter.addListener( @@ -25,33 +21,28 @@ module.exports = (NativeCodePush) => { // Use the downloaded package info. Native code will save the package info // so that the client knows what the current package version is. - return NativeCodePush.downloadUpdate(this) - .then((downloadedPackage) => { - downloadProgressSubscription && downloadProgressSubscription.remove(); - return Object.assign({}, downloadedPackage, local); - }) - .catch((error) => { - downloadProgressSubscription && downloadProgressSubscription.remove(); - // Rethrow the error for subsequent handlers down the promise chain. - throw error; - }); + try { + let downloadedPackage = await NativeCodePush.downloadUpdate(this); + downloadProgressSubscription && downloadProgressSubscription.remove(); + return Object.assign({}, downloadedPackage, local); + } finally { + downloadProgressSubscription && downloadProgressSubscription.remove(); + } }, isPending: false // A remote package could never be in a pending state }; const local = { - install(installMode = NativeCodePush.codePushInstallModeOnNextRestart, updateInstalledCallback) { + async install(installMode = NativeCodePush.codePushInstallModeOnNextRestart, updateInstalledCallback) { let localPackage = this; - return NativeCodePush.installUpdate(this, installMode) - .then(() => { - updateInstalledCallback && updateInstalledCallback(); - if (installMode == NativeCodePush.codePushInstallModeImmediate) { - NativeCodePush.restartApp(); - } else { - localPackage.isPending = true; // Mark the package as pending since it hasn't been applied yet - } - }); + await NativeCodePush.installUpdate(this, installMode); + updateInstalledCallback && updateInstalledCallback(); + if (installMode == NativeCodePush.codePushInstallModeImmediate) { + NativeCodePush.restartApp(); + } else { + localPackage.isPending = true; // Mark the package as pending since it hasn't been applied yet + } }, isPending: false // A local package wouldn't be pending until it was installed From e6115deec9cf37140d0335082ea6db8bf8c73371 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Wed, 23 Dec 2015 21:55:25 -0800 Subject: [PATCH 04/16] request-fetch-adapter --- request-fetch-adapter.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/request-fetch-adapter.js b/request-fetch-adapter.js index c3efb88..ee808fe 100644 --- a/request-fetch-adapter.js +++ b/request-fetch-adapter.js @@ -1,30 +1,30 @@ -module.exports.request = function request(verb, url, body, callback) { +let request = async (verb, url, body, callback) => { if (typeof body === "function") { callback = body; body = null; } var headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json' + "Accept": "application/json", + "Content-Type": "application/json" }; if (body && typeof body === "object") { body = JSON.stringify(body); } - var statusCode; - - fetch(url, { - method: verb, - headers: headers, - body: body - }).then(function(response) { - statusCode = response.status; - return response.text(); - }).then(function(body) { + try { + var statusCode; + let response = await fetch(url, { + method: verb, + headers: headers, + body: body + }); + + let statusCode = response.status; + let body = await response.text(); callback(null, {statusCode: statusCode, body: body}); - }).catch(function(err) { + } catch (err) { callback(err); - }); + } } From 9b87d7e2a89909250194a636da0e5c3b6fbd9f13 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Wed, 23 Dec 2015 22:53:58 -0800 Subject: [PATCH 05/16] feedback --- CodePush.js | 8 ++++---- .../CheckForUpdateTests/CheckForUpdateTestApp.js | 10 ++++------ .../CheckForUpdateTests/testcases/FirstUpdateTest.js | 4 ++-- .../CheckForUpdateTests/testcases/NewUpdateTest.js | 4 ++-- .../testcases/NoRemotePackageTest.js | 8 ++++---- .../testcases/RemotePackageAppVersionNewerTest.js | 6 +++--- .../CheckForUpdateTests/testcases/SamePackageTest.js | 4 ++-- .../testcases/SwitchDeploymentKeyTest.js | 6 +++--- .../DownloadProgressTests/resources/TestPackages.js | 4 ++-- .../testcases/DownloadProgressTest.js | 6 +++--- .../resources/IsFailedUpdateTestBundleV1.js | 4 ++-- .../resources/IsFailedUpdateTestBundleV2.js | 8 +++----- .../resources/NotifyApplicationReadyAndRestart.js | 4 ++-- .../resources/PassInstallModeImmediateTest.js | 6 ++---- .../resources/PassInstallModeOnNextRestartTest.js | 6 ++---- .../resources/PassInstallModeOnNextResumeTest.js | 6 ++---- .../resources/PassNotifyApplicationReadyTest.js | 6 ++---- .../resources/RollbackTestBundleV1.js | 6 +++--- .../resources/RollbackTestBundleV1Pass.js | 6 ++---- .../resources/RollbackTestBundleV2.js | 8 +++----- .../testcases/InstallModeImmediateTest.js | 4 ++-- .../testcases/InstallModeOnNextRestartTest.js | 4 ++-- .../testcases/InstallModeOnNextResumeTest.js | 4 ++-- .../InstallUpdateTests/testcases/IsFailedUpdateTest.js | 4 ++-- .../InstallUpdateTests/testcases/IsFirstRunTest.js | 4 ++-- .../InstallUpdateTests/testcases/IsPendingTest.js | 4 ++-- .../testcases/NotifyApplicationReadyTest.js | 4 ++-- .../InstallUpdateTests/testcases/RollbackTest.js | 4 ++-- .../utils/createTestCaseComponent.js | 4 ++-- package-mixins.js | 3 +-- 30 files changed, 71 insertions(+), 88 deletions(-) diff --git a/CodePush.js b/CodePush.js index a688669..8889d2a 100644 --- a/CodePush.js +++ b/CodePush.js @@ -1,8 +1,8 @@ 'use strict'; import { Alert } from "./AlertAdapter"; -let NativeCodePush = require("react-native").NativeModules.CodePush; -let PackageMixins = require("./package-mixins")(NativeCodePush); +const NativeCodePush = require("react-native").NativeModules.CodePush; +const PackageMixins = require("./package-mixins")(NativeCodePush); import requestFetchAdapter from "./request-fetch-adapter.js"; import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; import semver from "semver"; @@ -25,7 +25,7 @@ async function checkForUpdate(deploymentKey = null) { * dynamically "redirecting" end-users at different * deployments (e.g. an early access deployment for insiders). */ - let config = deploymentKey ? Object.assign({}, nativeConfig, { deploymentKey }) + let config = deploymentKey ? { ...nativeConfig, ...{ deploymentKey } } : nativeConfig; let sdk = getPromisifiedSdk(requestFetchAdapter, config); // Use dynamically overridden getCurrentPackage() during tests. @@ -58,7 +58,7 @@ async function checkForUpdate(deploymentKey = null) { if (!update || update.updateAppVersion || (update.packageHash === localPackage.packageHash)) { return null; } else { - let remotePackage = Object.assign(update, PackageMixins.remote); + let remotePackage = { ...update, ...PackageMixins.remote }; remotePackage.failedInstall = await NativeCodePush.isFailedUpdate(remotePackage.packageHash); return remotePackage; } diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp.js index 22250cc..3161a34 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp.js @@ -1,17 +1,15 @@ "use strict"; -import React from "react-native"; - -let { +import React, { AppRegistry, ScrollView, StyleSheet, Text, TouchableOpacity, View, -} = React; +} from "react-native"; -let TESTS = [ +const TESTS = [ require("./testcases/FirstUpdateTest"), require("./testcases/NewUpdateTest"), require("./testcases/NoRemotePackageTest"), @@ -65,7 +63,7 @@ let CheckForUpdateTestApp = React.createClass({ } }); -let styles = StyleSheet.create({ +const styles = StyleSheet.create({ container: { backgroundColor: "white", marginTop: 40, diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js index bf27f6a..c06f8aa 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js @@ -2,9 +2,9 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js index 393fdd2..b1c1369 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js @@ -2,9 +2,9 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js index 5464e7a..fa82568 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js @@ -2,14 +2,14 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; -let serverPackage = null; -let localPackage = {}; +const serverPackage = null; +const localPackage = {}; let NoRemotePackageTest = createTestCaseComponent( "NoRemotePackageTest", diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js index 50f9d57..df432ca 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js @@ -2,14 +2,14 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; import { updateAppVersionPackage as serverPackage } from "../resources/testPackages"; -let localPackage = {}; +const localPackage = {}; let RemotePackageAppVersionNewerTest = createTestCaseComponent( "RemotePackageAppVersionNewerTest", diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js index ba401f7..f6e3285 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js @@ -2,9 +2,9 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js index caceded..1bf0be8 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js @@ -2,16 +2,16 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; import { serverPackage } from "../resources/testPackages"; const localPackage = {}; -let deploymentKey = "myKey123"; +const deploymentKey = "myKey123"; let SwitchDeploymentKeyTest = createTestCaseComponent( "SwitchDeploymentKeyTest", diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/resources/TestPackages.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/resources/TestPackages.js index ae3254c..d13201c 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/resources/TestPackages.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/resources/TestPackages.js @@ -1,6 +1,6 @@ -let { Platform } = require("react-native"); +import { Platform } from "react-native"; -let packages = [ +const packages = [ { downloadUrl: "smallFile", description: "Angry flappy birds", diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js index 7841f66..096ab7b 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js @@ -2,13 +2,13 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import testPackages from "../resources/TestPackages"; -let localPackage = {}; +const localPackage = {}; let saveProgress; function checkReceivedAndExpectedBytesEqual() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js index 72ee0dc..819693e 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js @@ -8,8 +8,8 @@ import React, { } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; let IsFailedUpdateTest = React.createClass({ diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV2.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV2.js index da8f2f4..08fda7a 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV2.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV2.js @@ -1,13 +1,11 @@ "use strict"; -import React from "react-native"; -import CodePush from "react-native-code-push"; - -let { +import React, { AppRegistry, Text, View, -} = React; +} from "react-native"; +import CodePush from "react-native-code-push"; let IsFailedUpdateTest = React.createClass({ componentDidMount() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js index 338e2ae..a74ba09 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js @@ -3,8 +3,8 @@ import React from "react-native"; import { Platform, AppRegistry, Text, View } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; -let RCTTestModule = React.NativeModules.TestModule; +const NativeCodePush = React.NativeModules.CodePush; +const RCTTestModule = React.NativeModules.TestModule; let NotifyApplicationReadyTest = React.createClass({ getInitialState() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeImmediateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeImmediateTest.js index d93d8dc..ef8e17d 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeImmediateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeImmediateTest.js @@ -1,12 +1,10 @@ "use strict"; -import React from "react-native"; - -let { +import React, { AppRegistry, Text, View, -} = React; +} from "react-native"; let InstallModeImmediateTest = React.createClass({ render() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextRestartTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextRestartTest.js index 7743f49..e525da3 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextRestartTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextRestartTest.js @@ -1,12 +1,10 @@ "use strict"; -import React from "react-native"; - -let { +import React, { AppRegistry, Text, View, -} = React; +} from "react-native"; let InstallModeOnNextRestartTest = React.createClass({ render() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextResumeTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextResumeTest.js index cfd0a98..491a391 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextResumeTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassInstallModeOnNextResumeTest.js @@ -1,12 +1,10 @@ "use strict"; -import React from "react-native"; - -let { +import React, { AppRegistry, Text, View, -} = React; +} from "react-native"; let InstallModeOnNextResumeTest = React.createClass({ render() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassNotifyApplicationReadyTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassNotifyApplicationReadyTest.js index 5f426c7..df457b6 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassNotifyApplicationReadyTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/PassNotifyApplicationReadyTest.js @@ -1,12 +1,10 @@ "use strict"; -import React from "react-native"; - -let { +import React, { AppRegistry, Text, View, -} = React; +} from "react-native"; let NotifyApplicationReadyTest = React.createClass({ render() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js index 1877c84..33f7ebe 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js @@ -8,9 +8,9 @@ import React, { } from "react-native"; import CodePush from "react-native-code-push"; -let RCTTestModule = React.NativeModules.TestModule; -let NativeCodePush = React.NativeModules.CodePush; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const RCTTestModule = React.NativeModules.TestModule; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); let RollbackTest = React.createClass({ async componentDidMount() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.js index 2f8b87f..b6d2ed7 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1Pass.js @@ -1,12 +1,10 @@ "use strict"; -import React from "react-native"; - -let { +import React, { AppRegistry, Text, View, -} = React; +} from "react-native"; let RollbackTest = React.createClass({ render() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV2.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV2.js index 12c9ce7..8b348a6 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV2.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV2.js @@ -1,13 +1,11 @@ "use strict"; -import React from "react-native"; -import CodePush from "react-native-code-push"; - -let { +import React, { AppRegistry, Text, View, -} = React; +} from "react-native"; +import CodePush from "react-native-code-push"; let RollbackTest = React.createClass({ componentDidMount() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js index 640b0fe..ede635f 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js @@ -3,9 +3,9 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; let remotePackage = require("../resources/remotePackage"); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js index 5fa78fa..a383040 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js @@ -3,9 +3,9 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; let remotePackage = require("../resources/remotePackage"); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js index 8596d61..c1109da 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js @@ -3,9 +3,9 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; let remotePackage = require("../resources/remotePackage"); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js index 59a787f..d796645 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js @@ -3,9 +3,9 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; let remotePackage = require("../resources/remotePackage"); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js index d31f910..748b8b0 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js @@ -3,9 +3,9 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; let remotePackage = require("../resources/remotePackage"); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js index bd6825a..b5ae325 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js @@ -3,9 +3,9 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; let remotePackage = require("../resources/remotePackage"); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js index df233f1..bd7fd49 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js @@ -3,9 +3,9 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; let remotePackage = require("../resources/remotePackage"); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js index 6d4cd3e..0a64935 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js @@ -3,9 +3,9 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -let PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; let remotePackage = require("../resources/remotePackage"); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js index 9af45e3..498af1e 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js @@ -2,10 +2,10 @@ import React from "react-native"; import { DeviceEventEmitter, Text, View } from "react-native"; -let NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; // RCTTestModule is not implemented yet for RN Android. -let RCTTestModule = React.NativeModules.TestModule || {}; +const RCTTestModule = React.NativeModules.TestModule || {}; function createTestCaseComponent(displayName, description, setUp, runTest, passAfterRun = true) { let TestCaseComponent = React.createClass({ diff --git a/package-mixins.js b/package-mixins.js index a74ee11..b4a89d6 100644 --- a/package-mixins.js +++ b/package-mixins.js @@ -23,8 +23,7 @@ export default (NativeCodePush) => { // so that the client knows what the current package version is. try { let downloadedPackage = await NativeCodePush.downloadUpdate(this); - downloadProgressSubscription && downloadProgressSubscription.remove(); - return Object.assign({}, downloadedPackage, local); + return { ...downloadedPackage, ...local }; } finally { downloadProgressSubscription && downloadProgressSubscription.remove(); } From a981a763ee90f36e4a4d97747bc6b648514c0414 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Wed, 23 Dec 2015 22:54:51 -0800 Subject: [PATCH 06/16] feedback --- CodePush.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodePush.js b/CodePush.js index 8889d2a..55108f2 100644 --- a/CodePush.js +++ b/CodePush.js @@ -209,7 +209,7 @@ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCall if (typeof syncOptions.updateDialog !== "object") { syncOptions.updateDialog = CodePush.DEFAULT_UPDATE_DIALOG; } else { - syncOptions.updateDialog = Object.assign({}, CodePush.DEFAULT_UPDATE_DIALOG, syncOptions.updateDialog); + syncOptions.updateDialog = { ...CodePush.DEFAULT_UPDATE_DIALOG, ...syncOptions.updateDialog }; } return await new Promise((resolve, reject) => { From f62da660232643465f21d91ba75a7021aebb3567 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Wed, 23 Dec 2015 23:52:33 -0800 Subject: [PATCH 07/16] feedback --- CodePush.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/CodePush.js b/CodePush.js index 55108f2..5d84446 100644 --- a/CodePush.js +++ b/CodePush.js @@ -17,7 +17,7 @@ async function checkForUpdate(deploymentKey = null) { * for their specific deployment and version and which are actually * different from the CodePush update they have already installed. */ - let nativeConfig = await getConfiguration(); + const nativeConfig = await getConfiguration(); /* * If a deployment key was explicitly provided, * then let's override the one we retrieved @@ -25,11 +25,11 @@ async function checkForUpdate(deploymentKey = null) { * dynamically "redirecting" end-users at different * deployments (e.g. an early access deployment for insiders). */ - let config = deploymentKey ? { ...nativeConfig, ...{ deploymentKey } } + const config = deploymentKey ? { ...nativeConfig, ...{ deploymentKey } } : nativeConfig; - let sdk = getPromisifiedSdk(requestFetchAdapter, config); + const sdk = getPromisifiedSdk(requestFetchAdapter, config); // Use dynamically overridden getCurrentPackage() during tests. - let localPackage = await module.exports.getCurrentPackage(); + const localPackage = await module.exports.getCurrentPackage(); /* * If the app has a previously installed update, and that update * was targetted at the same app version that is currently running, @@ -38,10 +38,10 @@ async function checkForUpdate(deploymentKey = null) { * to send the app version to the server, since we are interested * in any updates for current app store version, regardless of hash. */ - let queryPackage = localPackage && localPackage.appVersion && semver.compare(localPackage.appVersion, config.appVersion) === 0 + const queryPackage = localPackage && localPackage.appVersion && semver.compare(localPackage.appVersion, config.appVersion) === 0 ? localPackage : { appVersion: config.appVersion }; - let update = await sdk.queryUpdateWithCurrentPackage(queryPackage); + const update = await sdk.queryUpdateWithCurrentPackage(queryPackage); /* * There are three cases where checkForUpdate will resolve to null: * ---------------------------------------------------------------- @@ -257,16 +257,16 @@ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCall } }; -var CodePush = { +export default { AcquisitionSdk: Sdk, - checkForUpdate: checkForUpdate, - getConfiguration: getConfiguration, - getCurrentPackage: getCurrentPackage, - log: log, + checkForUpdate, + getConfiguration, + getCurrentPackage, + log, notifyApplicationReady: NativeCodePush.notifyApplicationReady, restartApp: NativeCodePush.restartApp, - setUpTestDependencies: setUpTestDependencies, - sync: sync, + setUpTestDependencies, + sync, InstallMode: { IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart @@ -293,5 +293,3 @@ var CodePush = { title: "Update available" } }; - -export default CodePush; From 53073a527ff568d0c4a276a7f7dee97ccaf6fa48 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Wed, 23 Dec 2015 23:54:44 -0800 Subject: [PATCH 08/16] feedback --- CodePush.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CodePush.js b/CodePush.js index 5d84446..9df31ec 100644 --- a/CodePush.js +++ b/CodePush.js @@ -1,11 +1,12 @@ -'use strict'; +"use strict"; +import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; import { Alert } from "./AlertAdapter"; +import requestFetchAdapter from "./request-fetch-adapter.js"; +import semver from "semver"; + const NativeCodePush = require("react-native").NativeModules.CodePush; const PackageMixins = require("./package-mixins")(NativeCodePush); -import requestFetchAdapter from "./request-fetch-adapter.js"; -import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; -import semver from "semver"; async function checkForUpdate(deploymentKey = null) { /* From 36e90ac591ca6dc9b8dab4f62f108822646152a3 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 24 Dec 2015 00:00:43 -0800 Subject: [PATCH 09/16] feedback --- .../CheckForUpdateTests/testcases/FirstUpdateTest.js | 6 +++--- .../CheckForUpdateTests/testcases/NewUpdateTest.js | 6 +++--- .../CheckForUpdateTests/testcases/NoRemotePackageTest.js | 4 ++-- .../testcases/RemotePackageAppVersionNewerTest.js | 6 +++--- .../CheckForUpdateTests/testcases/SamePackageTest.js | 6 +++--- .../testcases/SwitchDeploymentKeyTest.js | 7 +++---- .../DownloadProgressTests/DownloadProgressTestApp.js | 6 ++---- .../testcases/DownloadProgressTest.js | 7 ++++--- .../resources/CheckIsFirstRunAndPassTest.js | 1 - .../resources/IsFailedUpdateTestBundleV1.js | 4 ++-- .../resources/NotifyApplicationReadyAndRestart.js | 1 + .../InstallUpdateTests/resources/RollbackTestBundleV1.js | 2 +- .../testcases/InstallModeImmediateTest.js | 5 +++-- .../testcases/InstallModeOnNextRestartTest.js | 5 +++-- .../testcases/InstallModeOnNextResumeTest.js | 5 +++-- .../InstallUpdateTests/testcases/IsFailedUpdateTest.js | 5 +++-- .../InstallUpdateTests/testcases/IsFirstRunTest.js | 4 ++-- .../InstallUpdateTests/testcases/IsPendingTest.js | 5 +++-- .../testcases/NotifyApplicationReadyTest.js | 5 +++-- .../InstallUpdateTests/testcases/RollbackTest.js | 5 +++-- .../CodePushDemoAppTests/utils/createTestCaseComponent.js | 2 +- 21 files changed, 51 insertions(+), 46 deletions(-) diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js index c06f8aa..1e293e7 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js @@ -2,13 +2,13 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; - import { serverPackage } from "../resources/testPackages"; + +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); const localPackage = {}; let FirstUpdateTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js index b1c1369..52c00b4 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js @@ -2,14 +2,14 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; - import { serverPackage, localPackage } from "../resources/testPackages"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); + let NewUpdateTest = createTestCaseComponent( "NewUpdateTest", "should return an update when server has a package that is newer than the current one", diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js index fa82568..2264832 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NoRemotePackageTest.js @@ -2,12 +2,12 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); const serverPackage = null; const localPackage = {}; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js index df432ca..afc4951 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js @@ -2,13 +2,13 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; - import { updateAppVersionPackage as serverPackage } from "../resources/testPackages"; + +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); const localPackage = {}; let RemotePackageAppVersionNewerTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js index f6e3285..76aac9a 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SamePackageTest.js @@ -2,13 +2,13 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; - import { serverPackage } from "../resources/testPackages"; + +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); const localPackage = serverPackage; let SamePackageTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js index 1bf0be8..4a6f4aa 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js @@ -2,15 +2,14 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; - import { serverPackage } from "../resources/testPackages"; -const localPackage = {}; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); +const localPackage = {}; const deploymentKey = "myKey123"; let SwitchDeploymentKeyTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/DownloadProgressTestApp.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/DownloadProgressTestApp.js index 65cf112..0b0b1bc 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/DownloadProgressTestApp.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/DownloadProgressTestApp.js @@ -1,15 +1,13 @@ "use strict"; -import React from "react-native"; - -let { +import React, { AppRegistry, ScrollView, StyleSheet, Text, TouchableOpacity, View, -} = React; +} from "react-native"; let TESTS = [ require("./testcases/DownloadProgressTest") diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js index 096ab7b..ee7bd98 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests/testcases/DownloadProgressTest.js @@ -2,13 +2,14 @@ import React from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; - import testPackages from "../resources/TestPackages"; + +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); const localPackage = {}; + let saveProgress; function checkReceivedAndExpectedBytesEqual() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/CheckIsFirstRunAndPassTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/CheckIsFirstRunAndPassTest.js index 54e2ad5..fe05015 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/CheckIsFirstRunAndPassTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/CheckIsFirstRunAndPassTest.js @@ -5,7 +5,6 @@ import React, { Text, View, } from "react-native"; - import CodePush from "react-native-code-push"; let IsFirstRunTest = React.createClass({ diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js index 819693e..a0528ee 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/IsFailedUpdateTestBundleV1.js @@ -6,11 +6,11 @@ import React, { Text, View, } from "react-native"; - import CodePush from "react-native-code-push"; +import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; + const NativeCodePush = React.NativeModules.CodePush; const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); -import createMockAcquisitionSdk from "../../utils/mockAcquisitionSdk"; let IsFailedUpdateTest = React.createClass({ getInitialState() { diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js index a74ba09..59c496c 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/NotifyApplicationReadyAndRestart.js @@ -3,6 +3,7 @@ import React from "react-native"; import { Platform, AppRegistry, Text, View } from "react-native"; import CodePush from "react-native-code-push"; + const NativeCodePush = React.NativeModules.CodePush; const RCTTestModule = React.NativeModules.TestModule; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js index 33f7ebe..565ab06 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/resources/RollbackTestBundleV1.js @@ -6,8 +6,8 @@ import React, { Text, View, } from "react-native"; - import CodePush from "react-native-code-push"; + const RCTTestModule = React.NativeModules.TestModule; const NativeCodePush = React.NativeModules.CodePush; const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js index ede635f..7c74f3d 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeImmediateTest.js @@ -3,11 +3,12 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); + let remotePackage = require("../resources/remotePackage"); let InstallModeImmediateTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js index a383040..9381951 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextRestartTest.js @@ -3,11 +3,12 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); + let remotePackage = require("../resources/remotePackage"); let InstallModeOnNextRestartTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js index c1109da..ed695e7 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/InstallModeOnNextResumeTest.js @@ -3,11 +3,12 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); + let remotePackage = require("../resources/remotePackage"); let InstallModeOnNextResumeTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js index d796645..5669de1 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFailedUpdateTest.js @@ -3,11 +3,12 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); + let remotePackage = require("../resources/remotePackage"); let IsFailedUpdateTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js index 748b8b0..f8c28cd 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsFirstRunTest.js @@ -3,11 +3,11 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); let remotePackage = require("../resources/remotePackage"); let IsFirstRunTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js index b5ae325..3e61f71 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/IsPendingTest.js @@ -3,11 +3,12 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); + let remotePackage = require("../resources/remotePackage"); let IsPendingTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js index bd7fd49..d77e125 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/NotifyApplicationReadyTest.js @@ -3,11 +3,12 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); + let remotePackage = require("../resources/remotePackage"); let NotifyApplicationReadyTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js index 0a64935..d002965 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests/testcases/RollbackTest.js @@ -3,11 +3,12 @@ import React from "react-native"; import { DeviceEventEmitter, Platform, AppRegistry } from "react-native"; import CodePush from "react-native-code-push"; -const NativeCodePush = React.NativeModules.CodePush; import createTestCaseComponent from "../../utils/createTestCaseComponent"; -const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); import assert from "assert"; +const NativeCodePush = React.NativeModules.CodePush; +const PackageMixins = require("react-native-code-push/package-mixins.js")(NativeCodePush); + let remotePackage = require("../resources/remotePackage"); let RollbackTest = createTestCaseComponent( diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js index 498af1e..719fbd5 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/utils/createTestCaseComponent.js @@ -2,8 +2,8 @@ import React from "react-native"; import { DeviceEventEmitter, Text, View } from "react-native"; -const NativeCodePush = React.NativeModules.CodePush; +const NativeCodePush = React.NativeModules.CodePush; // RCTTestModule is not implemented yet for RN Android. const RCTTestModule = React.NativeModules.TestModule || {}; From 3078277bb440e124c1a5337297a6b0e71a002d27 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 24 Dec 2015 00:02:27 -0800 Subject: [PATCH 10/16] feedback --- CodePush.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodePush.js b/CodePush.js index 9df31ec..6f993cd 100644 --- a/CodePush.js +++ b/CodePush.js @@ -201,7 +201,7 @@ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCall return CodePush.SyncStatus.UPDATE_INSTALLED; }; - if (!remotePackage || (remotePackage.failedInstall && syncOptions.ignoreFailedUpdates)) { + if (!remotePackage || remotePackage.failedInstall && syncOptions.ignoreFailedUpdates) { syncStatusChangeCallback(CodePush.SyncStatus.UP_TO_DATE); return (CodePush.SyncStatus.UP_TO_DATE); } else if (syncOptions.updateDialog) { From 222f1f602254890c80dec010e3b69d461b2e32e9 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 24 Dec 2015 00:05:04 -0800 Subject: [PATCH 11/16] feedback --- package-mixins.js | 2 +- request-fetch-adapter.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/package-mixins.js b/package-mixins.js index b4a89d6..40038dc 100644 --- a/package-mixins.js +++ b/package-mixins.js @@ -22,7 +22,7 @@ export default (NativeCodePush) => { // Use the downloaded package info. Native code will save the package info // so that the client knows what the current package version is. try { - let downloadedPackage = await NativeCodePush.downloadUpdate(this); + const downloadedPackage = await NativeCodePush.downloadUpdate(this); return { ...downloadedPackage, ...local }; } finally { downloadProgressSubscription && downloadProgressSubscription.remove(); diff --git a/request-fetch-adapter.js b/request-fetch-adapter.js index ee808fe..b8ee2a6 100644 --- a/request-fetch-adapter.js +++ b/request-fetch-adapter.js @@ -13,8 +13,7 @@ let request = async (verb, url, body, callback) => { body = JSON.stringify(body); } - try { - var statusCode; + try { let response = await fetch(url, { method: verb, headers: headers, @@ -23,7 +22,7 @@ let request = async (verb, url, body, callback) => { let statusCode = response.status; let body = await response.text(); - callback(null, {statusCode: statusCode, body: body}); + callback(null, { statusCode, body }); } catch (err) { callback(err); } From df02e01de65ca71d2fb07216ad0a44b9f06c0435 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 24 Dec 2015 00:06:01 -0800 Subject: [PATCH 12/16] feedback --- request-fetch-adapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/request-fetch-adapter.js b/request-fetch-adapter.js index b8ee2a6..fec3f63 100644 --- a/request-fetch-adapter.js +++ b/request-fetch-adapter.js @@ -14,13 +14,13 @@ let request = async (verb, url, body, callback) => { } try { - let response = await fetch(url, { + const response = await fetch(url, { method: verb, headers: headers, body: body }); - let statusCode = response.status; + const statusCode = response.status; let body = await response.text(); callback(null, { statusCode, body }); } catch (err) { From 482be153d3511e128012513012712aa8fbd3f937 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 24 Dec 2015 00:08:35 -0800 Subject: [PATCH 13/16] feedback --- CodePush.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CodePush.js b/CodePush.js index 6f993cd..11b00ce 100644 --- a/CodePush.js +++ b/CodePush.js @@ -201,9 +201,9 @@ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCall return CodePush.SyncStatus.UPDATE_INSTALLED; }; - if (!remotePackage || remotePackage.failedInstall && syncOptions.ignoreFailedUpdates) { + if (!remotePackage || (remotePackage.failedInstall && syncOptions.ignoreFailedUpdates)) { syncStatusChangeCallback(CodePush.SyncStatus.UP_TO_DATE); - return (CodePush.SyncStatus.UP_TO_DATE); + return CodePush.SyncStatus.UP_TO_DATE; } else if (syncOptions.updateDialog) { // updateDialog supports any truthy value (e.g. true, "goo", 12), // but we should treat a non-object value as just the default dialog From 45c4e74d1a390f2eff1a82cecd710bbbaffde8d2 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 24 Dec 2015 01:00:17 -0800 Subject: [PATCH 14/16] feedback --- CodePush.js | 4 ++-- request-fetch-adapter.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CodePush.js b/CodePush.js index 11b00ce..d7ff97e 100644 --- a/CodePush.js +++ b/CodePush.js @@ -187,9 +187,9 @@ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCall await CodePush.notifyApplicationReady(); syncStatusChangeCallback(CodePush.SyncStatus.CHECKING_FOR_UPDATE); - let remotePackage = await checkForUpdate(syncOptions.deploymentKey); + const remotePackage = await checkForUpdate(syncOptions.deploymentKey); - let doDownloadAndInstall = async () => { + const doDownloadAndInstall = async () => { syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE); let localPackage = await remotePackage.download(downloadProgressCallback); diff --git a/request-fetch-adapter.js b/request-fetch-adapter.js index fec3f63..5571ceb 100644 --- a/request-fetch-adapter.js +++ b/request-fetch-adapter.js @@ -21,7 +21,7 @@ let request = async (verb, url, body, callback) => { }); const statusCode = response.status; - let body = await response.text(); + const body = await response.text(); callback(null, { statusCode, body }); } catch (err) { callback(err); From 89d5c14d144827c5c03337300b267d64c087cefa Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 24 Dec 2015 12:44:36 -0800 Subject: [PATCH 15/16] feedback --- CodePush.js | 14 +++++++------- package-mixins.js | 4 +++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CodePush.js b/CodePush.js index d7ff97e..4664284 100644 --- a/CodePush.js +++ b/CodePush.js @@ -59,13 +59,13 @@ async function checkForUpdate(deploymentKey = null) { if (!update || update.updateAppVersion || (update.packageHash === localPackage.packageHash)) { return null; } else { - let remotePackage = { ...update, ...PackageMixins.remote }; + const remotePackage = { ...update, ...PackageMixins.remote }; remotePackage.failedInstall = await NativeCodePush.isFailedUpdate(remotePackage.packageHash); return remotePackage; } } -let getConfiguration = (() => { +const getConfiguration = (() => { let config; return async function getConfiguration() { if (config) { @@ -80,7 +80,7 @@ let getConfiguration = (() => { })(); async function getCurrentPackage() { - let localPackage = await NativeCodePush.getCurrentPackage(); + const localPackage = await NativeCodePush.getCurrentPackage(); localPackage.failedInstall = await NativeCodePush.isFailedUpdate(localPackage.packageHash); localPackage.isFirstRun = await NativeCodePush.isFirstRun(localPackage.packageHash); return localPackage; @@ -88,7 +88,7 @@ async function getCurrentPackage() { function getPromisifiedSdk(requestFetchAdapter, config) { // Use dynamically overridden AcquisitionSdk during tests. - let sdk = new module.exports.AcquisitionSdk(requestFetchAdapter, config); + const sdk = new module.exports.AcquisitionSdk(requestFetchAdapter, config); sdk.queryUpdateWithCurrentPackage = (queryPackage) => { return new Promise((resolve, reject) => { module.exports.AcquisitionSdk.prototype.queryUpdateWithCurrentPackage.call(sdk, queryPackage, (err, update) => { @@ -128,7 +128,7 @@ function setUpTestDependencies(testSdk, providedTestConfig, testNativeBridge) { * when an update is available. */ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback) { - let syncOptions = { + const syncOptions = { deploymentKey: null, ignoreFailedUpdates: true, @@ -191,7 +191,7 @@ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCall const doDownloadAndInstall = async () => { syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE); - let localPackage = await remotePackage.download(downloadProgressCallback); + const localPackage = await remotePackage.download(downloadProgressCallback); syncStatusChangeCallback(CodePush.SyncStatus.INSTALLING_UPDATE); await localPackage.install(syncOptions.installMode, () => { @@ -215,7 +215,7 @@ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCall return await new Promise((resolve, reject) => { let message = null; - let dialogButtons = [{ + const dialogButtons = [{ text: null, onPress: async () => { resolve(await doDownloadAndInstall()); diff --git a/package-mixins.js b/package-mixins.js index 40038dc..6cd8eb5 100644 --- a/package-mixins.js +++ b/package-mixins.js @@ -1,3 +1,5 @@ +"use strict"; + import { DeviceEventEmitter } from "react-native"; // This function is used to augment remote and local @@ -34,7 +36,7 @@ export default (NativeCodePush) => { const local = { async install(installMode = NativeCodePush.codePushInstallModeOnNextRestart, updateInstalledCallback) { - let localPackage = this; + const localPackage = this; await NativeCodePush.installUpdate(this, installMode); updateInstalledCallback && updateInstalledCallback(); if (installMode == NativeCodePush.codePushInstallModeImmediate) { From ad3cd211f83e9965c77ee6b065b30932a9bb2a09 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 24 Dec 2015 14:31:02 -0800 Subject: [PATCH 16/16] a few bugfixes --- CodePush.js | 8 +++-- .../testcases/FirstUpdateTest.js | 4 +-- .../testcases/NewUpdateTest.js | 4 +-- .../RemotePackageAppVersionNewerTest.js | 2 +- .../testcases/SwitchDeploymentKeyTest.js | 4 +-- request-fetch-adapter.js | 36 ++++++++++--------- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/CodePush.js b/CodePush.js index 4664284..384cc59 100644 --- a/CodePush.js +++ b/CodePush.js @@ -2,10 +2,10 @@ import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; import { Alert } from "./AlertAdapter"; -import requestFetchAdapter from "./request-fetch-adapter.js"; +import requestFetchAdapter from "./request-fetch-adapter"; import semver from "semver"; -const NativeCodePush = require("react-native").NativeModules.CodePush; +let NativeCodePush = require("react-native").NativeModules.CodePush; const PackageMixins = require("./package-mixins")(NativeCodePush); async function checkForUpdate(deploymentKey = null) { @@ -258,7 +258,7 @@ async function sync(options = {}, syncStatusChangeCallback, downloadProgressCall } }; -export default { +const CodePush = { AcquisitionSdk: Sdk, checkForUpdate, getConfiguration, @@ -294,3 +294,5 @@ export default { title: "Update available" } }; + +export default CodePush; \ No newline at end of file diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js index 1e293e7..21fbd0e 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/FirstUpdateTest.js @@ -23,8 +23,8 @@ let FirstUpdateTest = createTestCaseComponent( }; }, async () => { - let update = await CodePush.checkForUpdate() - assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote), "checkForUpdate did not return the update from the server"); + let update = await CodePush.checkForUpdate(); + assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote, failedInstall: false }), "checkForUpdate did not return the update from the server"); } ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js index 52c00b4..c097c16 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/NewUpdateTest.js @@ -22,8 +22,8 @@ let NewUpdateTest = createTestCaseComponent( }; }, async () => { - let update = await CodePush.checkForUpdate() - assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote), "checkForUpdate did not return the update from the server"); + let update = await CodePush.checkForUpdate(); + assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote, failedInstall: false }), "checkForUpdate did not return the update from the server"); } ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js index afc4951..db22e67 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/RemotePackageAppVersionNewerTest.js @@ -23,7 +23,7 @@ let RemotePackageAppVersionNewerTest = createTestCaseComponent( }; }, async () => { - let update = await CodePush.checkForUpdate() + let update = await CodePush.checkForUpdate(); assert(!update, "checkForUpdate should not return an update if remote package is of a different binary version"); } ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js index 4a6f4aa..25e9568 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests/testcases/SwitchDeploymentKeyTest.js @@ -24,8 +24,8 @@ let SwitchDeploymentKeyTest = createTestCaseComponent( }; }, async () => { - let update = await CodePush.checkForUpdate(deploymentKey) - assert.deepEqual(update, Object.assign(serverPackage, PackageMixins.remote), "checkForUpdate did not return the update from the server"); + let update = await CodePush.checkForUpdate(deploymentKey); + assert.equal(JSON.stringify(update), JSON.stringify({ ...serverPackage, ...PackageMixins.remote, failedInstall: false }), "checkForUpdate did not return the update from the server"); } ); diff --git a/request-fetch-adapter.js b/request-fetch-adapter.js index 5571ceb..1ccd3df 100644 --- a/request-fetch-adapter.js +++ b/request-fetch-adapter.js @@ -1,29 +1,33 @@ -let request = async (verb, url, body, callback) => { +"use strict"; + +export default { + async request(verb, url, body, callback) { if (typeof body === "function") { - callback = body; - body = null; + callback = body; + body = null; } var headers = { - "Accept": "application/json", - "Content-Type": "application/json" + "Accept": "application/json", + "Content-Type": "application/json" }; if (body && typeof body === "object") { - body = JSON.stringify(body); + body = JSON.stringify(body); } try { - const response = await fetch(url, { - method: verb, - headers: headers, - body: body - }); + const response = await fetch(url, { + method: verb, + headers: headers, + body: body + }); - const statusCode = response.status; - const body = await response.text(); - callback(null, { statusCode, body }); + const statusCode = response.status; + const body = await response.text(); + callback(null, { statusCode, body }); } catch (err) { - callback(err); + callback(err); } -} + } +};