tests work on android, mostly on iOS

This commit is contained in:
scottbommarito 2016-05-25 14:26:35 -07:00
Родитель 5260dc1550
Коммит e87f1977d0
7 изменённых файлов: 1131 добавлений и 976 удалений

Просмотреть файл

@ -418,15 +418,15 @@ if (NativeCodePush) {
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background
},
SyncStatus: {
CHECKING_FOR_UPDATE: 0,
AWAITING_USER_ACTION: 1,
DOWNLOADING_PACKAGE: 2,
INSTALLING_UPDATE: 3,
UP_TO_DATE: 4, // The running app is up-to-date
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress.
UNKNOWN_ERROR: -1
UP_TO_DATE: 0, // The running app is up-to-date
UPDATE_INSTALLED: 1, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
UPDATE_IGNORED: 2, // The app had an optional update and the end-user chose to ignore it
UNKNOWN_ERROR: 3,
SYNC_IN_PROGRESS: 4, // There is an ongoing "sync" operation in progress.
CHECKING_FOR_UPDATE: 5,
AWAITING_USER_ACTION: 6,
DOWNLOADING_PACKAGE: 7,
INSTALLING_UPDATE: 8
},
UpdateState: {
RUNNING: NativeCodePush.codePushUpdateStateRunning,

Просмотреть файл

@ -114,6 +114,7 @@ public class CodePush implements ReactPackage {
initializeUpdateAfterRestart();
}
// USED FOR TESTING SO THAT IT CAN CONNECT TO DEBUG SERVER
public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode, String serverUrl) {
this(deploymentKey, mainActivity, isDebugMode);
this.serverUrl = serverUrl;
@ -515,6 +516,10 @@ public class CodePush implements ReactPackage {
e.printStackTrace();
saveFailedUpdate(updatePackage);
promise.reject(e);
} catch (CodePushMalformedDataException e) {
e.printStackTrace();
saveFailedUpdate(updatePackage);
promise.reject(e);
}
return null;

Просмотреть файл

@ -21,7 +21,7 @@ public class MainActivity extends ReactActivity {
*/
@Override
protected String getMainComponentName() {
return "TestCodePush";
return "CODE_PUSH_TEST_APP_NAME";
}
/**

Просмотреть файл

@ -6,52 +6,44 @@ module.exports = {
checkForUpdate: function(testApp, onSuccess, onError, deploymentKey) {
return CodePush.checkForUpdate(deploymentKey)
.then((remotePackage) => {
testApp.checkUpdateSuccess(remotePackage);
return onSuccess && onSuccess(remotePackage);
return testApp.checkUpdateSuccess(remotePackage).then(() => { return onSuccess && onSuccess(remotePackage); });
}, (error) => {
testApp.checkUpdateError(error);
return onError && onError(error);
return testApp.checkUpdateError(error).then(() => { return onError && onError(error); });
});
},
download: function(testApp, onSuccess, onError, remotePackage) {
return remotePackage.download()
.then((localPackage) => {
testApp.downloadSuccess(localPackage);
return onSuccess && onSuccess(localPackage);
return testApp.downloadSuccess(localPackage).then(() => { return onSuccess && onSuccess(localPackage); });
}, (error) => {
testApp.downloadError(error);
return onError && onError(error);
return testApp.downloadError(error).then(() => { return onError && onError(error); });
});
},
install: function(testApp, onSuccess, onError, installMode, minBackgroundDuration, localPackage) {
return localPackage.install(installMode, minBackgroundDuration)
.then(() => {
// Since immediate installs cannot be reliably logged, we only log "UPDATE_INSTALLED" if it is a resume or restart update.
if (installMode !== CodePush.InstallMode.IMMEDIATE) testApp.installSuccess();
// Since immediate installs cannot be reliably logged (due to async network calls), we only log "UPDATE_INSTALLED" if it is a resume or restart update.
if (installMode !== CodePush.InstallMode.IMMEDIATE) return testApp.installSuccess().then(() => { return onSuccess && onSuccess(); });
return onSuccess && onSuccess();
}, () => {
testApp.installError();
return onError && onError();
return testApp.installError().then(() => { return onError && onError(); });
});
},
checkAndInstall: function(testApp, onSuccess, onError, installMode, minBackgroundDuration) {
return this.checkForUpdate(testApp,
this.download.bind(undefined, testApp,
this.install.bind(undefined, testApp, onSuccess, onError, installMode, minBackgroundDuration),
onError));
var installUpdate = this.install.bind(this, testApp, onSuccess, onError, installMode, minBackgroundDuration);
var downloadUpdate = this.download.bind(this, testApp, installUpdate, onError);
return this.checkForUpdate(testApp, downloadUpdate, onError);
},
sync: function(testApp, onSyncStatus, onSyncError, options) {
return CodePush.sync(options)
.then((status) => {
testApp.onSyncStatus(status);
return onSyncStatus(status);
return testApp.onSyncStatus(status).then(() => { return onSyncStatus(status); });
}, (error) => {
testApp.onSyncError(error);
return onSyncError(error);
return testApp.onSyncError(error).then(() => { return onSyncError(error); });
});
}
}

Просмотреть файл

@ -1,12 +1,13 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
* CodePush React-Native Test App
*/
import React, {
Component
} from 'react';
import {
AppRegistry,
Component,
StyleSheet,
Text,
View
@ -16,63 +17,57 @@ import CodePush from "react-native-code-push";
var testScenario = require("./CODE_PUSH_INDEX_JS_PATH");
var TestCodePush = React.createClass({
/** A promise that maintains synchronous sending of the test messages. */
var testMessageQueue;
var CODE_PUSH_TEST_APP_NAME = React.createClass({
// CodePush API Callbacks
// checkForUpdate
checkUpdateSuccess(remotePackage) {
if (remotePackage) {
if (!remotePackage.failedInstall) {
this.setStateAndSendMessage("There is an update available. Remote package:" + JSON.stringify(remotePackage), "CHECK_UPDATE_AVAILABLE", [remotePackage]);
return this.setStateAndSendMessage("There is an update available. Remote package:" + JSON.stringify(remotePackage), "CHECK_UPDATE_AVAILABLE", [remotePackage]);
} else {
this.setStateAndSendMessage("An update is available but failed previously. Remote package:" + JSON.stringify(remotePackage), "UPDATE_FAILED_PREVIOUSLY");
return this.setStateAndSendMessage("An update is available but failed previously. Remote package:" + JSON.stringify(remotePackage), "UPDATE_FAILED_PREVIOUSLY");
}
} else {
this.setStateAndSendMessage("The application is up to date.", "CHECK_UP_TO_DATE");
return this.setStateAndSendMessage("The application is up to date.", "CHECK_UP_TO_DATE");
}
},
checkUpdateError(error) {
this.setStateAndSendMessage("An error occured while checking for updates.", "CHECK_ERROR");
this.setState({
message: this.state.message + "\n...\n" + error
});
return this.setStateAndSendMessage("An error occured while checking for updates:\n" + error, "CHECK_ERROR");
},
// remotePackage.download
downloadSuccess(localPackage) {
this.setStateAndSendMessage("Download succeeded.", "DOWNLOAD_SUCCEEDED", [localPackage]);
return this.setStateAndSendMessage("Download succeeded.", "DOWNLOAD_SUCCEEDED", [localPackage]);
},
downloadError(error) {
this.setStateAndSendMessage("Download error.", "DOWNLOAD_ERROR");
this.setState({
message: this.state.message + "\n...\n" + error
});
return this.setStateAndSendMessage("Download error:\n" + error, "DOWNLOAD_ERROR");
},
// localPackage.install
installSuccess() {
this.setStateAndSendMessage("Update installed.", "UPDATE_INSTALLED");
return this.setStateAndSendMessage("Update installed.", "UPDATE_INSTALLED");
},
installError() {
this.setStateAndSendMessage("Install error.", "INSTALL_ERROR");
return this.setStateAndSendMessage("Install error.", "INSTALL_ERROR");
},
// sync
onSyncStatus(status) {
this.setStateAndSendMessage("Sync status " + status + " received.", "SYNC_STATUS", [status]);
return this.setStateAndSendMessage("Sync status " + status + " received.", "SYNC_STATUS", [status]);
},
onSyncError(error) {
this.setStateAndSendMessage("Sync error.", "SYNC_ERROR");
this.setState({
message: this.state.message + "\n...\n" + error
});
return this.setStateAndSendMessage("Sync error " + error + " received.", "SYNC_STATUS", [CodePush.SyncStatus.UNKNOWN_ERROR]);
},
// Test Output Methods
readyAfterUpdate(callback) {
this.setStateAndSendMessage("Ready after update.", "DEVICE_READY_AFTER_UPDATE", callback);
return this.setStateAndSendMessage("Ready after update.", "DEVICE_READY_AFTER_UPDATE", undefined, callback);
},
sendCurrentAndPendingPackage() {
@ -82,32 +77,43 @@ var TestCodePush = React.createClass({
return CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING);
})
.then((currentPackage) => {
this.setStateAndSendMessage("Current package: " + currentPackage, "CURRENT_PACKAGE", [currentPackage ? currentPackage.packageHash : null]);
return this.setStateAndSendMessage("Current package: " + currentPackage, "CURRENT_PACKAGE", [currentPackage ? currentPackage.packageHash : null]);
});
},
setStateAndSendMessage(message, testMessage, args) {
setStateAndSendMessage(message, testMessage, args, callback) {
this.setState({
message: this.state.message + "\n...\n" + message
});
this.sendTestMessage(testMessage, args);
return this.sendTestMessage(testMessage, args, callback);
},
sendTestMessage(message, args, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
callback && callback(xhr.response);
}
};
function makeNetworkCall() {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open("POST", "CODE_PUSH_SERVER_URL/reportTestMessage", true);
var body = JSON.stringify({ message: message, args: args});
console.log("Sending test message body: " + body);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
callback && callback(xhr.response);
resolve();
}
};
xhr.open("POST", "CODE_PUSH_SERVER_URL/reportTestMessage", true);
var body = JSON.stringify({ message: message, args: args});
console.log("Sending test message body: " + body);
xhr.setRequestHeader("Content-type", "application/json");
xhr.send(body);
xhr.setRequestHeader("Content-type", "application/json");
xhr.send(body);
});
}
if (!testMessageQueue) testMessageQueue = makeNetworkCall();
else testMessageQueue = testMessageQueue.then(makeNetworkCall);
return testMessageQueue;
},
@ -130,10 +136,7 @@ var TestCodePush = React.createClass({
CodePush React-Native Plugin Tests
</Text>
<Text style={styles.instructions}>
{testScenario.getScenarioName()}
</Text>
<Text style={styles.instructions}>
{this.state.message}
{testScenario.getScenarioName()}{this.state.message}
</Text>
</View>
);
@ -159,4 +162,4 @@ const styles = StyleSheet.create({
},
});
AppRegistry.registerComponent('TestCodePush', () => TestCodePush);
AppRegistry.registerComponent('CODE_PUSH_TEST_APP_NAME', () => CODE_PUSH_TEST_APP_NAME);

Просмотреть файл

@ -13,10 +13,14 @@
#import "CodePush.h"
#import "RCTLog.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTSetLogThreshold(RCTLogLevelInfo);
NSURL *jsCodeLocation;
/**
@ -48,7 +52,7 @@
jsCodeLocation = [CodePush bundleURL];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"CodePushDemoApp"
moduleName:@"CODE_PUSH_TEST_APP_NAME"
initialProperties:nil
launchOptions:launchOptions];

Разница между файлами не показана из-за своего большого размера Загрузить разницу