diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index 2b23fec..331e7dd 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -73,7 +73,7 @@ public class CodePush implements ReactPackage { private String appVersion; private int buildVersion; private String deploymentKey; - private final String serverUrl = "https://codepush.azurewebsites.net/"; + private String serverUrl = "https://codepush.azurewebsites.net/"; private Activity mainActivity; private Context applicationContext; @@ -111,6 +111,11 @@ public class CodePush implements ReactPackage { clearDebugCacheIfNeeded(); } + public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode, String serverUrl) { + this(deploymentKey, mainActivity, isDebugMode); + this.serverUrl = serverUrl; + } + private void clearDebugCacheIfNeeded() { if (isDebugMode && isPendingUpdate(null)) { // This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78 diff --git a/gulpfile.js b/gulpfile.js index b3b5270..6f6fdce 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,7 +4,6 @@ var child_process = require("child_process"); var Q = require("q"); var runSequence = require("run-sequence"); -var sourcePath = "./www"; var testPath = "./test"; var binPath = "./bin"; var tsFiles = "/**/*.ts"; @@ -129,7 +128,7 @@ function runTests(callback, options) { } gulp.task("compile", function (callback) { - runSequence("compile-src", "compile-test", callback); + runSequence("compile-test", callback); }); gulp.task("compile-test", function () { @@ -142,16 +141,6 @@ gulp.task("compile-test", function () { .pipe(gulp.dest(path.join(binPath, testPath))); }); -gulp.task("compile-src", function () { - var ts = require("gulp-typescript"); - var insert = require("gulp-insert"); - - return gulp.src([sourcePath + tsFiles]) - .pipe(ts(tsCompileOptions)) - .pipe(insert.prepend(compiledSourceWarningMessage)) - .pipe(gulp.dest(path.join(binPath, sourcePath))); -}); - gulp.task("tslint", function () { var tslint = require('gulp-tslint'); @@ -193,7 +182,7 @@ gulp.task("tslint", function () { } } - return gulp.src([sourcePath + tsFiles, testPath + tsFiles]) + return gulp.src([testPath + tsFiles]) .pipe(tslint({ configuration: config })) .pipe(tslint.report("verbose")); }); diff --git a/package.json b/package.json index 22ee925..71083be 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,17 @@ "url": "https://github.com/Microsoft/react-native-code-push" }, "dependencies": { - "code-push": "1.8.0-beta" + "archiver": "latest", + "body-parser": "latest", + "code-push": "1.8.0-beta", + "del": "latest", + "express": "latest", + "gulp-typescript": "2.12.2", + "gulp-insert": "latest", + "gulp-tslint": "latest", + "mkdirp": "latest", + "q": "^1.4.1", + "run-sequence": "latest" }, "rnpm": { "android": { diff --git a/test/template/android/app/src/main/java/com/microsoft/codepush/test/MainActivity.java b/test/template/android/app/src/main/java/com/microsoft/codepush/test/MainActivity.java index 2b2a36f..d02c688 100644 --- a/test/template/android/app/src/main/java/com/microsoft/codepush/test/MainActivity.java +++ b/test/template/android/app/src/main/java/com/microsoft/codepush/test/MainActivity.java @@ -1,4 +1,4 @@ -package com.microsoft.codepushdemoapp; +package com.microsoft.codepush.test; import com.facebook.react.ReactActivity; import com.facebook.react.ReactPackage; @@ -21,7 +21,7 @@ public class MainActivity extends ReactActivity { */ @Override protected String getMainComponentName() { - return "CodePushDemoApp"; + return "TestCodePush"; } /** @@ -41,7 +41,7 @@ public class MainActivity extends ReactActivity { protected List getPackages() { return Arrays.asList( new MainReactPackage(), - new CodePush("deployment-key-here", this, BuildConfig.DEBUG) + new CodePush("CODE_PUSH_ANDROID_DEPLOYMENT_KEY", this, BuildConfig.DEBUG, "CODE_PUSH_SERVER_URL") ); } } diff --git a/test/template/index.js b/test/template/index.js index ae5a05c..d0b8f06 100644 --- a/test/template/index.js +++ b/test/template/index.js @@ -16,7 +16,7 @@ import CodePush from "react-native-code-push"; var testScenario = require("./CODE_PUSH_INDEX_JS_PATH"); -var RNTestTester = React.createClass({ +var TestCodePush = React.createClass({ // CodePush API Callbacks // checkForUpdate @@ -33,6 +33,9 @@ var RNTestTester = React.createClass({ }, checkUpdateError(error) { this.setStateAndSendMessage("An error occured while checking for updates.", "CHECK_ERROR"); + this.setState({ + message: this.state.message + "\n...\n" + error + }); }, // remotePackage.download @@ -41,6 +44,9 @@ var RNTestTester = React.createClass({ }, downloadError(error) { this.setStateAndSendMessage("Download error.", "DOWNLOAD_ERROR"); + this.setState({ + message: this.state.message + "\n...\n" + error + }); }, // localPackage.install @@ -57,6 +63,9 @@ var RNTestTester = React.createClass({ }, onSyncError(error) { this.setStateAndSendMessage("Sync error.", "SYNC_ERROR"); + this.setState({ + message: this.state.message + "\n...\n" + error + }); }, @@ -150,4 +159,4 @@ const styles = StyleSheet.create({ }, }); -AppRegistry.registerComponent('RNTestTester', () => RNTestTester); \ No newline at end of file +AppRegistry.registerComponent('TestCodePush', () => TestCodePush); \ No newline at end of file diff --git a/test/template/scenarios/scenarioCheckForUpdate.js b/test/template/scenarios/scenarioCheckForUpdate.js index 73942dd..e816133 100644 --- a/test/template/scenarios/scenarioCheckForUpdate.js +++ b/test/template/scenarios/scenarioCheckForUpdate.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); module.exports = { startTest: function(testApp) { diff --git a/test/template/scenarios/scenarioCheckForUpdateCustomKey.js b/test/template/scenarios/scenarioCheckForUpdateCustomKey.js index ceb169f..3c5fb09 100644 --- a/test/template/scenarios/scenarioCheckForUpdateCustomKey.js +++ b/test/template/scenarios/scenarioCheckForUpdateCustomKey.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); module.exports = { startTest: function(testApp) { diff --git a/test/template/scenarios/scenarioDownloadUpdate.js b/test/template/scenarios/scenarioDownloadUpdate.js index c35b193..984c4b1 100644 --- a/test/template/scenarios/scenarioDownloadUpdate.js +++ b/test/template/scenarios/scenarioDownloadUpdate.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); module.exports = { startTest: function(testApp) { diff --git a/test/template/scenarios/scenarioInstall.js b/test/template/scenarios/scenarioInstall.js index 66f8f39..3929c8b 100644 --- a/test/template/scenarios/scenarioInstall.js +++ b/test/template/scenarios/scenarioInstall.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); module.exports = { startTest: function(testApp) { diff --git a/test/template/scenarios/scenarioInstallOnRestartWithRevert.js b/test/template/scenarios/scenarioInstallOnRestartWithRevert.js index 03453bc..ec5d81f 100644 --- a/test/template/scenarios/scenarioInstallOnRestartWithRevert.js +++ b/test/template/scenarios/scenarioInstallOnRestartWithRevert.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioInstallOnResumeWithRevert.js b/test/template/scenarios/scenarioInstallOnResumeWithRevert.js index f760021..e9fbaa0 100644 --- a/test/template/scenarios/scenarioInstallOnResumeWithRevert.js +++ b/test/template/scenarios/scenarioInstallOnResumeWithRevert.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioInstallWithRevert.js b/test/template/scenarios/scenarioInstallWithRevert.js index 9275474..1d91cb9 100644 --- a/test/template/scenarios/scenarioInstallWithRevert.js +++ b/test/template/scenarios/scenarioInstallWithRevert.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioRestart.js b/test/template/scenarios/scenarioRestart.js index 21128ed..e55377b 100644 --- a/test/template/scenarios/scenarioRestart.js +++ b/test/template/scenarios/scenarioRestart.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioSync.js b/test/template/scenarios/scenarioSync.js index 948673d..895c508 100644 --- a/test/template/scenarios/scenarioSync.js +++ b/test/template/scenarios/scenarioSync.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioSync2x.js b/test/template/scenarios/scenarioSync2x.js index fd4567b..0319e50 100644 --- a/test/template/scenarios/scenarioSync2x.js +++ b/test/template/scenarios/scenarioSync2x.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioSyncMandatoryDefault.js b/test/template/scenarios/scenarioSyncMandatoryDefault.js index 7810ffa..2e4f616 100644 --- a/test/template/scenarios/scenarioSyncMandatoryDefault.js +++ b/test/template/scenarios/scenarioSyncMandatoryDefault.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioSyncMandatoryRestart.js b/test/template/scenarios/scenarioSyncMandatoryRestart.js index eb84542..90990e1 100644 --- a/test/template/scenarios/scenarioSyncMandatoryRestart.js +++ b/test/template/scenarios/scenarioSyncMandatoryRestart.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioSyncMandatoryResume.js b/test/template/scenarios/scenarioSyncMandatoryResume.js index 3a7978a..dfa9793 100644 --- a/test/template/scenarios/scenarioSyncMandatoryResume.js +++ b/test/template/scenarios/scenarioSyncMandatoryResume.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioSyncRestartDelay.js b/test/template/scenarios/scenarioSyncRestartDelay.js index 8a591b9..73cf38d 100644 --- a/test/template/scenarios/scenarioSyncRestartDelay.js +++ b/test/template/scenarios/scenarioSyncRestartDelay.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioSyncResume.js b/test/template/scenarios/scenarioSyncResume.js index cefed9a..a1fb9cd 100644 --- a/test/template/scenarios/scenarioSyncResume.js +++ b/test/template/scenarios/scenarioSyncResume.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/scenarioSyncResumeDelay.js b/test/template/scenarios/scenarioSyncResumeDelay.js index 27a00fe..77f3d53 100644 --- a/test/template/scenarios/scenarioSyncResumeDelay.js +++ b/test/template/scenarios/scenarioSyncResumeDelay.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/updateDeviceReady.js b/test/template/scenarios/updateDeviceReady.js index 329f345..3153326 100644 --- a/test/template/scenarios/updateDeviceReady.js +++ b/test/template/scenarios/updateDeviceReady.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); module.exports = { startTest: function(testApp) { diff --git a/test/template/scenarios/updateNARConditional.js b/test/template/scenarios/updateNARConditional.js index ce7318b..147ee38 100644 --- a/test/template/scenarios/updateNARConditional.js +++ b/test/template/scenarios/updateNARConditional.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/updateNotifyApplicationReady.js b/test/template/scenarios/updateNotifyApplicationReady.js index 8441291..7ba5e1e 100644 --- a/test/template/scenarios/updateNotifyApplicationReady.js +++ b/test/template/scenarios/updateNotifyApplicationReady.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/template/scenarios/updateSync.js b/test/template/scenarios/updateSync.js index 8956744..41d1ca7 100644 --- a/test/template/scenarios/updateSync.js +++ b/test/template/scenarios/updateSync.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); module.exports = { startTest: function(testApp) { diff --git a/test/template/scenarios/updateSync2x.js b/test/template/scenarios/updateSync2x.js index 94fbf24..60aba43 100644 --- a/test/template/scenarios/updateSync2x.js +++ b/test/template/scenarios/updateSync2x.js @@ -1,4 +1,4 @@ -var CodePushWrapper = require("./codePushWrapper.js"); +var CodePushWrapper = require("../codePushWrapper.js"); module.exports = { startTest: function(testApp) { diff --git a/test/test.ts b/test/test.ts index 9cd1404..b1e4b63 100644 --- a/test/test.ts +++ b/test/test.ts @@ -42,12 +42,16 @@ class RNProjectManager extends ProjectManager { var promises: Q.Promise[] = []; fs.readdirSync(directoryFrom).forEach(file => { - var fileStats: fs.Stats = fs.statSync(file); + var fileStats: fs.Stats; var fileInFrom: string = path.join(directoryFrom, file); var fileInTo: string = path.join(directoryTo, file); + try { fileStats = fs.statSync(fileInFrom); } catch (e) { /* fs.statSync throws if the file doesn't exist. */ } + // If it is a file, just copy directly - if (fileStats.isFile()) promises.push(ProjectManager.copyFile(fileInFrom, fileInTo)); + if (fileStats && fileStats.isFile()) { + promises.push(ProjectManager.copyFile(fileInFrom, fileInTo, true)); + } else { // If it is a directory, create the directory if it doesn't exist on the target and then copy over if (!fs.existsSync(fileInTo)) mkdirp.sync(fileInTo); @@ -55,14 +59,16 @@ class RNProjectManager extends ProjectManager { } }); - return Q.all(promises); + // Chain promise so that it maintains Q.Promise type instead of Q.Promise + return Q.all(promises).then(() => { return null; }); } // React-Native adds a "com." to the front of the name you provide, so provide the namespace with the "com." removed - return ProjectManager.execChildProcess("react-native init " + appNamespace.slice("com.".length, appNamespace.length), { cwd: projectDirectory + "/.." }) + return ProjectManager.execChildProcess("react-native init " + appName + " --package " + appNamespace, { cwd: projectDirectory }, true) // Copy over the template // Overwrites existing files with the files that are provided in the template (MainActivity.java, AppDelegate.m) - .then(copyDirectoryRecursively.bind(this, templatePath, projectDirectory)); + .then(copyDirectoryRecursively.bind(this, templatePath, path.join(projectDirectory, PluginTestingFramework.TestAppName))) + .then(ProjectManager.execChildProcess.bind(undefined, "npm install " + PluginTestingFramework.thisPluginPath, { cwd: path.join(projectDirectory, PluginTestingFramework.TestAppName) })); } /** @@ -71,12 +77,12 @@ class RNProjectManager extends ProjectManager { public setupScenario(projectDirectory: string, appId: string, templatePath: string, jsPath: string, targetPlatform: Platform.IPlatform, version?: string): Q.Promise { var indexHtml = "index.js"; var templateIndexPath = path.join(templatePath, indexHtml); - var destinationIndexPath = path.join(projectDirectory, indexHtml); + var destinationIndexPath = path.join(projectDirectory, PluginTestingFramework.TestAppName, indexHtml); var scenarioJs = "scenarios/" + jsPath; - var packageFile = eval("(" + fs.readFileSync("./package.json", "utf8") + ")"); - var pluginVersion = packageFile.version; + // var packageFile = eval("(" + fs.readFileSync("./package.json", "utf8") + ")"); + // var pluginVersion = packageFile.version; console.log("Setting up scenario " + jsPath + " in " + projectDirectory); @@ -84,23 +90,26 @@ class RNProjectManager extends ProjectManager { return ProjectManager.copyFile(templateIndexPath, destinationIndexPath, true) .then(ProjectManager.replaceString.bind(undefined, destinationIndexPath, ProjectManager.SERVER_URL_PLACEHOLDER, targetPlatform.getServerUrl())) .then(ProjectManager.replaceString.bind(undefined, destinationIndexPath, ProjectManager.INDEX_JS_PLACEHOLDER, scenarioJs)) - .then(ProjectManager.replaceString.bind(undefined, destinationIndexPath, ProjectManager.CODE_PUSH_APP_VERSION_PLACEHOLDER, version)); + .then(ProjectManager.replaceString.bind(undefined, destinationIndexPath, ProjectManager.CODE_PUSH_APP_VERSION_PLACEHOLDER, version)) + // Chain promise so that it maintains Q.Promise type instead of Q.Promise + .then(() => { return null; }); } /** * Creates a CodePush update package zip for a project. */ public createUpdateArchive(projectDirectory: string, targetPlatform: Platform.IPlatform, isDiff?: boolean): Q.Promise { - var bundleFolder: string = path.join(projectDirectory, "CodePush/"); + var bundleFolder: string = path.join(projectDirectory, PluginTestingFramework.TestAppName, "CodePush/"); var bundlePath: string = path.join(bundleFolder, "./main.jsbundle"); var deferred = Q.defer(); fs.exists(bundleFolder, (exists) => { if (exists) fs.mkdirSync(bundleFolder); - deferred.resolve(); + deferred.resolve(undefined); }); return deferred.promise - .then(ProjectManager.execChildProcess.bind(this, "react-native bundle --platform " + targetPlatform.getName() + " --entry-file index." + targetPlatform.getName() + ".js --bundle-output " + bundlePath + " --assets-dest " + bundleFolder + " --dev false", { cwd: projectDirectory })) - .then(() => { return bundlePath; }); + .then(ProjectManager.execChildProcess.bind(undefined, "react-native bundle --platform " + targetPlatform.getName() + " --entry-file index." + targetPlatform.getName() + ".js --bundle-output " + bundlePath + " --assets-dest " + bundleFolder + " --dev false", + { cwd: path.join(projectDirectory, PluginTestingFramework.TestAppName) })) + .then(ProjectManager.archiveFolder.bind(undefined, bundleFolder, path.join(projectDirectory, PluginTestingFramework.TestAppName, "update.zip"), isDiff)); } /** JSON file containing the platforms the plugin is currently installed for. @@ -112,7 +121,7 @@ class RNProjectManager extends ProjectManager { * "ios": false * } */ - private static platformJSONPath: string = "./platforms.json"; + private static platformsJSON: string = "platforms.json"; /** * Prepares a specific platform for tests. @@ -120,41 +129,60 @@ class RNProjectManager extends ProjectManager { public preparePlatform(projectFolder: string, targetPlatform: Platform.IPlatform): Q.Promise { var deferred= Q.defer(); + var platformsJSONPath = path.join(projectFolder, RNProjectManager.platformsJSON); + // We create a JSON file in the project folder to contain the installed platforms. // Check the file to see if the plugin for this platform has been installed and update the file appropriately. - fs.exists(this.platformJSONPath, (exists) => { + fs.exists(platformsJSONPath, (exists) => { if (!exists) { - fs.writeFileSync(this.platformJSONPath, "{}"); + fs.writeFileSync(platformsJSONPath, "{}"); } - var platformJSON = eval("(" + fs.readFileSync(this.platformJSONPath, "utf8") + ")"); - if (platformJSON[targetPlatform.getName()]) deferred.reject("Platform " + targetPlatform.getName() + " is already installed!"); + var platformJSON = eval("(" + fs.readFileSync(platformsJSONPath, "utf8") + ")"); + if (platformJSON[targetPlatform.getName()] === true) deferred.reject("Platform " + targetPlatform.getName() + " is already installed!"); else { platformJSON[targetPlatform.getName()] = true; - fs.writeFileSync(this.platformJSONPath, JSON.stringify(platformJSON)); - deferred.resolve(); + fs.writeFileSync(platformsJSONPath, JSON.stringify(platformJSON)); + deferred.resolve(undefined); } }); + var innerProjectFolder: string = path.join(projectFolder, PluginTestingFramework.TestAppName); + // Install the CodePush plugin for the platform. return deferred.promise - .then(() => { + .then(() => { if (targetPlatform === Platform.Android.getInstance()) { - // Link through RNPM - return ProjectManager.execChildProcess("rnpm link react-native-code-push", { cwd: projectFolder }) - // NOTE: this "then" can be removed when RNPM supports dynamic linking - .then(ProjectManager.replaceString.bind(undefined, path.join(projectFolder, "android", "app", "build.gradle"), - "apply from: \"react.gradle\"", - "apply from: \"react.gradle\"\napply from: \"" + path.join(projectFolder, "node_modules", "react-native-code-push", "android", "codepush.gradle") + "\"")); + // Add to android/app/build.gradle + var buildGradle = path.join(innerProjectFolder, "android", "app", "build.gradle"); + ProjectManager.replaceString(buildGradle, + "apply from: \"../../node_modules/react-native/react.gradle\"", + "apply from: \"../../node_modules/react-native/react.gradle\"\napply from: \"" + path.join(innerProjectFolder, "node_modules", "react-native-code-push", "android", "codepush.gradle") + "\""); + ProjectManager.replaceString(buildGradle, + "// From node_modules", + "\n compile project(':react-native-code-push') // From node_modules"); + // Add to android/settings.gradle + ProjectManager.replaceString(path.join(innerProjectFolder, "android", "settings.gradle"), + "include ':app'", + "include ':app', ':react-native-code-push'\nproject(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')"); + // Replace the MainActivity.java with the correct server url and deployment key + var mainActivity = path.join(innerProjectFolder, "android", "app", "src", "main", "java", "com", "microsoft", "codepush", "test", "MainActivity.java"); + ProjectManager.replaceString(mainActivity, ProjectManager.SERVER_URL_PLACEHOLDER, Platform.Android.getInstance().getServerUrl()); + ProjectManager.replaceString(mainActivity, ProjectManager.ANDROID_KEY_PLACEHOLDER, Platform.Android.getInstance().getDefaultDeploymentKey()); } else if (targetPlatform === Platform.IOS.getInstance()) { - var iOSProject: string = path.join(projectFolder, "iOS"); + var iOSProject: string = path.join(innerProjectFolder, "iOS"); // Create and install the Podfile return ProjectManager.execChildProcess("pod init", { cwd: iOSProject }) .then(ProjectManager.replaceString.bind(undefined, path.join(iOSProject, "Podfile"), "# use_frameworks!", - "use_frameworks!\n pod 'React', :path => './node_modules/react-native', :subspecs => [ 'Core', 'RCTImage', 'RCTNetwork', 'RCTText', 'RCTWebSocket', ]\n pod 'CodePush', :path => './node_modules/react-native-code-push'")) - .then(ProjectManager.execChildProcess("pod install", { cwd: iOSProject }); + "use_frameworks!\n pod 'React', :path => '../node_modules/react-native', :subspecs => [ 'Core', 'RCTImage', 'RCTNetwork', 'RCTText', 'RCTWebSocket', ]\n pod 'CodePush', :path => '../node_modules/react-native-code-push'")) + // Put the IOS deployment key in the Info.plist + .then(ProjectManager.replaceString.bind(undefined, path.join(iOSProject, PluginTestingFramework.TestAppName, "Info.plist"), + "\n", + "CodePushDeploymentKey\n\t" + Platform.IOS.getInstance().getDefaultDeploymentKey() + "\n\tCodePushServerURL\n\t" + Platform.IOS.getInstance().getServerUrl() + "\n\t\n")) + // Install the Pod + .then(ProjectManager.execChildProcess.bind(undefined, "pod install", { cwd: iOSProject })); } - }); + }, (error) => { /* The platform is already installed! */ console.log(error); return null; }); } /** @@ -171,7 +199,7 @@ class RNProjectManager extends ProjectManager { public runPlatform(projectFolder: string, targetPlatform: Platform.IPlatform): Q.Promise { console.log("Running project in " + projectFolder + " on " + targetPlatform.getName()); // Don't log the build output because iOS's build output is too verbose and overflows the buffer! - return ProjectManager.execChildProcess("react-native run-" + targetPlatform.getName(), { cwd: projectFolder }, false); + return ProjectManager.execChildProcess("react-native run-" + targetPlatform.getName(), { cwd: path.join(projectFolder, PluginTestingFramework.TestAppName) }); } }; diff --git a/typings/code-push-plugin-testing-framework.d.ts b/typings/code-push-plugin-testing-framework.d.ts index 2153c3e..f769740 100644 --- a/typings/code-push-plugin-testing-framework.d.ts +++ b/typings/code-push-plugin-testing-framework.d.ts @@ -273,7 +273,11 @@ declare module 'code-push-plugin-testing-framework/script/projectManager' { /** * Copies a file from a given location to another. */ - static copyFile(source: string, destination: string, overwrite: boolean): Q.Promise; + static copyFile(source: string, destination: string, overwrite: boolean): Q.Promise; + /** + * Archives the contents of targetFolder and puts it in an archive at archivePath. + */ + static archiveFolder(targetFolder: string, archivePath: string, isDiff: boolean): Q.Promise; } } @@ -370,6 +374,10 @@ declare module 'code-push-plugin-testing-framework/script/testUtil' { maxBuffer?: number; killSignal?: string; }, logOutput?: boolean): Q.Promise; + /** + * Returns the name of the plugin that is being tested. + */ + static getPluginName(): string; } } @@ -498,12 +506,15 @@ declare module 'code-push-plugin-testing-framework/script/test' { private testBuilders; /** Whether or not this.testBuilders directly contains any TestBuildIt objects */ private hasIts; + /** The function that create calls (used for describe.only) */ + private functionToUse; /** * describeName - used as the description in the call to describe * scenarioPath - if specified, will be set up before the tests run * testBuilders - the testBuilders to create within this describe call + * only - if true, use describe.only */ - constructor(describeName: string, testBuilders: TestBuilder[], scenarioPath?: string); + constructor(describeName: string, testBuilders: TestBuilder[], scenarioPath?: string, only?: boolean); /** * Called to create the test suite by the initializeTests function * @@ -521,12 +532,15 @@ declare module 'code-push-plugin-testing-framework/script/test' { private test; /** Whether or not the test should be run when "--core" is supplied */ private isCoreTest; + /** The function that create calls (used for it.only) */ + private functionToUse; /** * testName - used as the expectation in the call to it * test - the test to provide to it * isCoreTest - whether or not the test should run when "--core" is supplied + * only - if true, use it.only */ - constructor(testName: string, test: (projectManager: tm.ProjectManager, targetPlatform: platform.IPlatform, done: MochaDone) => void, isCoreTest: boolean); + constructor(testName: string, test: (projectManager: tm.ProjectManager, targetPlatform: platform.IPlatform, done: MochaDone) => void, isCoreTest: boolean, only?: boolean); /** * Called to create the test suite by the initializeTests function * @@ -560,6 +574,14 @@ declare module 'code-push-plugin-testing-framework/script/test' { * Waits for the next set of test messages sent by the app and asserts that they are equal to the expected messages */ export function verifyMessages(expectedMessages: (string | su.AppMessage)[], deferred: Q.Deferred): (requestBody: any) => void; + /** + * Sets up the server that the test app uses to send test messages and check for and download updates. + */ + export function setupServer(targetPlatform: platform.IPlatform): void; + /** + * Closes the server. + */ + export function cleanupServer(): void; /** * Call this function with a ProjectManager and an array of TestBuilderDescribe objects to run tests */