This commit is contained in:
Geoffrey Goh
2015-12-23 21:24:29 -08:00
parent aac19e25d6
commit ebd93b53eb
29 changed files with 309 additions and 425 deletions

View File

@@ -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;

View File

@@ -38,6 +38,7 @@ let CheckForUpdateTestApp = React.createClass({
</ScrollView>
);
}
return (
<View style={styles.container}>
<Text style={styles.row}>

View File

@@ -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");
}
);

View File

@@ -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;
export default NewUpdateTest;

View File

@@ -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;
export default NoRemotePackageTest;

View File

@@ -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;
export default RemotePackageAppVersionNewerTest;

View File

@@ -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;
export default SamePackageTest;

View File

@@ -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;
export default SwitchDeploymentKeyTest;

View File

@@ -49,4 +49,4 @@ let DownloadProgressTest = createTestCaseComponent(
}
);
module.exports = DownloadProgressTest;
export default DownloadProgressTest;

View File

@@ -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...";

View File

@@ -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...";

View File

@@ -11,6 +11,7 @@ let {
let IsFailedUpdateTest = React.createClass({
componentDidMount() {
// Should trigger a rollback.
CodePush.restartApp();
},
render() {

View File

@@ -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 (

View File

@@ -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 (

View File

@@ -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
);

View File

@@ -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
);

View File

@@ -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
);

View File

@@ -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
);

View File

@@ -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
);

View File

@@ -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");
}
);

View File

@@ -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
);

View File

@@ -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
);

View File

@@ -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 (

View File

@@ -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,

View File

@@ -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"

View File

@@ -44,6 +44,6 @@
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>CodePushDeploymentKey</key>
<string>5c73310a-cc93-4aa5-bf9f-81c6b648232c</string>
<string>deployment-key-here</string>
</dict>
</plist>

View File

@@ -1 +1 @@
require("./crossplatformdemo.js");
import "./crossplatformdemo.js";

View File

@@ -1 +1 @@
require("./crossplatformdemo.js");
import "./crossplatformdemo.js";

View File

@@ -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