mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-30 17:43:05 +08:00
solve async test messages with immediate problem
This commit is contained in:
@@ -29,12 +29,13 @@ Follow these steps to test your modifications to the plugin manually:
|
|||||||
npm install local_path_to_your_clone_of_this_repo
|
npm install local_path_to_your_clone_of_this_repo
|
||||||
```
|
```
|
||||||
- configure the plugin using the steps in the README.md
|
- configure the plugin using the steps in the README.md
|
||||||
|
- build and run your app on an emulator or device
|
||||||
|
|
||||||
## Test
|
## Test
|
||||||
|
|
||||||
### Environment setup
|
### Environment setup
|
||||||
|
|
||||||
First, make sure you can build the plugin by following the steps above.
|
First, make sure you have installed the dependencies for the plugin by following the steps above.
|
||||||
|
|
||||||
Then, make sure you have installed `gulp`.
|
Then, make sure you have installed `gulp`.
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,35 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
sync: function(testApp, onSyncStatus, onSyncError, options) {
|
sync: function(testApp, onSyncStatus, onSyncError, options) {
|
||||||
return CodePush.sync(options)
|
return CodePush.checkForUpdate()
|
||||||
.then((status) => {
|
.then(
|
||||||
return testApp.onSyncStatus(status).then(() => { return onSyncStatus(status); });
|
(remotePackage) => {
|
||||||
}, (error) => {
|
// Since immediate installs cannot be reliably logged (due to async network calls), we don't log "UPDATE_INSTALLED" when the installation is immediate.
|
||||||
return testApp.onSyncError(error).then(() => { return onSyncError(error); });
|
// However, to determine this, we must first figure out whether or not the package is mandatory because mandatory packages use a different install mode than regular updates.
|
||||||
});
|
// This requires an additional call to checkForUpdate before syncing.
|
||||||
|
var regularUpdateIsImmediate = options && options.installMode === CodePush.InstallMode.IMMEDIATE;
|
||||||
|
var mandatoryUpdateIsImmediate = !options || (options && (!options.mandatoryInstallMode || options.mandatoryInstallMode === CodePush.InstallMode.IMMEDIATE));
|
||||||
|
var isInstallImmediate = (remotePackage && remotePackage.isMandatory) ? mandatoryUpdateIsImmediate : regularUpdateIsImmediate;
|
||||||
|
|
||||||
|
return CodePush.sync(options)
|
||||||
|
.then((status) => {
|
||||||
|
if (!(isInstallImmediate && status === CodePush.SyncStatus.UPDATE_INSTALLED)) {
|
||||||
|
return testApp.onSyncStatus(status).then(() => { return onSyncStatus(status); });
|
||||||
|
}
|
||||||
|
return onSyncStatus(status);
|
||||||
|
}, (error) => {
|
||||||
|
return testApp.onSyncError(error).then(() => { return onSyncError(error); });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
return CodePush.sync(options)
|
||||||
|
.then((status) => {
|
||||||
|
// Should fail because the check for update failed, so no need to check whether the install is immediate.
|
||||||
|
return testApp.onSyncStatus(status).then(() => { return onSyncStatus(status); });
|
||||||
|
}, (error) => {
|
||||||
|
return testApp.onSyncError(error).then(() => { return onSyncError(error); });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,32 +23,6 @@
|
|||||||
|
|
||||||
NSURL *jsCodeLocation;
|
NSURL *jsCodeLocation;
|
||||||
|
|
||||||
/**
|
|
||||||
* Loading JavaScript code - uncomment the one you want.
|
|
||||||
*
|
|
||||||
* OPTION 1
|
|
||||||
* Load from development server. Start the server from the repository root:
|
|
||||||
*
|
|
||||||
* $ npm start
|
|
||||||
*
|
|
||||||
* To run on device, change `localhost` to the IP address of your computer
|
|
||||||
* (you can get this by typing `ifconfig` into the terminal and selecting the
|
|
||||||
* `inet` value under `en0:`) and make sure your computer and iOS device are
|
|
||||||
* on the same Wi-Fi network.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.includeRequire.runModule.bundle?dev=true&platform=ios"];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OPTION 2
|
|
||||||
* Load from pre-bundled file on disk. To re-generate the static bundle
|
|
||||||
* from the root of your project directory, run
|
|
||||||
*
|
|
||||||
* $ react-native bundle --minify
|
|
||||||
*
|
|
||||||
* see http://facebook.github.io/react-native/docs/runningondevice.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
jsCodeLocation = [CodePush bundleURL];
|
jsCodeLocation = [CodePush bundleURL];
|
||||||
|
|
||||||
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
|
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
|
||||||
|
|||||||
32
test/test.ts
32
test/test.ts
@@ -133,7 +133,7 @@ class RNAndroid extends Platform.Android implements RNPlatform {
|
|||||||
// In order to run on Android without the package manager, we must create a release APK and then sign it with the debug certificate.
|
// In order to run on Android without the package manager, we must create a release APK and then sign it with the debug certificate.
|
||||||
var androidDirectory: string = path.join(projectDirectory, PluginTestingFramework.TestAppName, "android");
|
var androidDirectory: string = path.join(projectDirectory, PluginTestingFramework.TestAppName, "android");
|
||||||
var apkPath = this.getBinaryPath(projectDirectory);
|
var apkPath = this.getBinaryPath(projectDirectory);
|
||||||
return TestUtil.getProcessOutput("./gradlew assembleRelease", { cwd: androidDirectory })
|
return TestUtil.getProcessOutput("./gradlew assembleRelease --daemon", { cwd: androidDirectory })
|
||||||
.then<string>(TestUtil.getProcessOutput.bind(undefined, "jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android " + apkPath + " androiddebugkey", { cwd: androidDirectory, noLogStdOut: true }));
|
.then<string>(TestUtil.getProcessOutput.bind(undefined, "jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android " + apkPath + " androiddebugkey", { cwd: androidDirectory, noLogStdOut: true }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,6 +240,10 @@ class RNIOS extends Platform.IOS implements RNPlatform {
|
|||||||
// The first time an iOS project is built, it fails because it does not finish building libReact.a before it builds the test app.
|
// The first time an iOS project is built, it fails because it does not finish building libReact.a before it builds the test app.
|
||||||
// Simply build again to fix the issue.
|
// Simply build again to fix the issue.
|
||||||
if (!RNIOS.iosFirstBuild[projectDirectory]) {
|
if (!RNIOS.iosFirstBuild[projectDirectory]) {
|
||||||
|
var iosBuildFolder = path.join(iOSProject, "build");
|
||||||
|
if (fs.existsSync(iosBuildFolder)) {
|
||||||
|
del.sync([iosBuildFolder], { force: true });
|
||||||
|
}
|
||||||
RNIOS.iosFirstBuild[projectDirectory] = true;
|
RNIOS.iosFirstBuild[projectDirectory] = true;
|
||||||
return this.buildApp(projectDirectory);
|
return this.buildApp(projectDirectory);
|
||||||
}
|
}
|
||||||
@@ -435,14 +439,13 @@ class RNProjectManager extends ProjectManager {
|
|||||||
return Q<string>(undefined)
|
return Q<string>(undefined)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Build if this scenario has not yet been built.
|
// Build if this scenario has not yet been built.
|
||||||
/* if (!RNProjectManager.currentScenarioHasBuilt[projectDirectory]) {
|
if (!RNProjectManager.currentScenarioHasBuilt[projectDirectory]) {
|
||||||
RNProjectManager.currentScenarioHasBuilt[projectDirectory] = true;
|
RNProjectManager.currentScenarioHasBuilt[projectDirectory] = true;
|
||||||
return (<RNPlatform><any>targetPlatform).buildApp(projectDirectory);
|
return (<RNPlatform><any>targetPlatform).buildApp(projectDirectory);
|
||||||
} */
|
}
|
||||||
return (<RNPlatform><any>targetPlatform).buildApp(projectDirectory);
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Uninstall the app so that the app's data doesn't carry over between tests.
|
// Uninstall the app so that the installation is clean and no files are left around for each test.
|
||||||
return targetPlatform.getEmulatorManager().uninstallApplication(PluginTestingFramework.TestNamespace);
|
return targetPlatform.getEmulatorManager().uninstallApplication(PluginTestingFramework.TestNamespace);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -1051,9 +1054,7 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
|
|||||||
.then<void>((updatePath: string) => {
|
.then<void>((updatePath: string) => {
|
||||||
PluginTestingFramework.updatePackagePath = updatePath;
|
PluginTestingFramework.updatePackagePath = updatePath;
|
||||||
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
||||||
return PluginTestingFramework.expectTestMessages([
|
return PluginTestingFramework.expectTestMessages([ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
|
|
||||||
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
|
|
||||||
})
|
})
|
||||||
.then<void>(() => {
|
.then<void>(() => {
|
||||||
targetPlatform.getEmulatorManager().restartApplication(PluginTestingFramework.TestNamespace);
|
targetPlatform.getEmulatorManager().restartApplication(PluginTestingFramework.TestNamespace);
|
||||||
@@ -1073,8 +1074,6 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
|
|||||||
PluginTestingFramework.updatePackagePath = updatePath;
|
PluginTestingFramework.updatePackagePath = updatePath;
|
||||||
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
||||||
return PluginTestingFramework.expectTestMessages([
|
return PluginTestingFramework.expectTestMessages([
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
|
|
||||||
// the update is immediate so the update will install
|
|
||||||
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE,
|
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE,
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UP_TO_DATE])]);
|
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UP_TO_DATE])]);
|
||||||
})
|
})
|
||||||
@@ -1155,7 +1154,6 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
|
|||||||
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
||||||
return PluginTestingFramework.expectTestMessages([
|
return PluginTestingFramework.expectTestMessages([
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
|
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
|
|
||||||
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
|
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
|
||||||
})
|
})
|
||||||
.then<void>(() => {
|
.then<void>(() => {
|
||||||
@@ -1178,8 +1176,6 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
|
|||||||
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
||||||
return PluginTestingFramework.expectTestMessages([
|
return PluginTestingFramework.expectTestMessages([
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
|
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
|
|
||||||
// the update is immediate so the update will install
|
|
||||||
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE,
|
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE,
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
|
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_IN_PROGRESS]),
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UP_TO_DATE])]);
|
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UP_TO_DATE])]);
|
||||||
@@ -1299,9 +1295,7 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
|
|||||||
.then<void>((updatePath: string) => {
|
.then<void>((updatePath: string) => {
|
||||||
PluginTestingFramework.updatePackagePath = updatePath;
|
PluginTestingFramework.updatePackagePath = updatePath;
|
||||||
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
||||||
return PluginTestingFramework.expectTestMessages([
|
return PluginTestingFramework.expectTestMessages([ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
|
|
||||||
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
|
|
||||||
})
|
})
|
||||||
.done(() => { done(); }, (e) => { done(e); });
|
.done(() => { done(); }, (e) => { done(e); });
|
||||||
}, false),
|
}, false),
|
||||||
@@ -1341,13 +1335,11 @@ var testBuilderDescribes: PluginTestingFramework.TestBuilderDescribe[] = [
|
|||||||
.then<void>((updatePath: string) => {
|
.then<void>((updatePath: string) => {
|
||||||
PluginTestingFramework.updatePackagePath = updatePath;
|
PluginTestingFramework.updatePackagePath = updatePath;
|
||||||
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
projectManager.runApplication(PluginTestingFramework.testRunDirectory, targetPlatform);
|
||||||
return PluginTestingFramework.expectTestMessages([
|
return PluginTestingFramework.expectTestMessages([ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
|
||||||
new ServerUtil.AppMessage(ServerUtil.TestMessage.SYNC_STATUS, [ServerUtil.TestMessage.SYNC_UPDATE_INSTALLED]),
|
|
||||||
ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]);
|
|
||||||
})
|
})
|
||||||
.done(() => { done(); }, (e) => { done(e); });
|
.done(() => { done(); }, (e) => { done(e); });
|
||||||
}, false)
|
}, false)
|
||||||
], undefined)
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
var rootTestBuilder = new PluginTestingFramework.TestBuilderDescribe("CodePush", testBuilderDescribes);
|
var rootTestBuilder = new PluginTestingFramework.TestBuilderDescribe("CodePush", testBuilderDescribes);
|
||||||
|
|||||||
Reference in New Issue
Block a user