Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 5ce2300

Browse files
authored
[Tests] Update configurations of test android app (#1775)
1 parent 35182ca commit 5ce2300

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

code-push-plugin-testing-framework/script/serverUtil.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ function setupServer(targetPlatform) {
2020
res.setHeader("Access-Control-Allow-Headers", "origin, content-type, accept, X-CodePush-SDK-Version");
2121
next();
2222
});
23-
app.get("/updateCheck", function (req, res) {
23+
app.get("/v0.1/public/codepush/update_check", function (req, res) {
2424
exports.updateCheckCallback && exports.updateCheckCallback(req);
2525
res.send(exports.updateResponse);
2626
console.log("Update check called from the app.");
2727
console.log("Request: " + JSON.stringify(req.query));
2828
console.log("Response: " + JSON.stringify(exports.updateResponse));
2929
});
30-
app.get("/download", function (req, res) {
30+
app.get("/v0.1/public/codepush/report_status/download", function (req, res) {
3131
console.log("Application downloading the package.");
3232
res.download(exports.updatePackagePath);
3333
});

code-push-plugin-testing-framework/script/testConfig.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ var DEFAULT_PLUGIN_PATH = path.join(__dirname, "../..");
1717
var NPM_PLUGIN_PATH = TestUtil_1.TestUtil.getPluginName();
1818
var SETUP_FLAG_NAME = "--setup";
1919
var RESTART_EMULATORS_FLAG_NAME = "--clean";
20+
var DEFAULT_PLUGIN_TGZ_NAME = TestUtil_1.TestUtil.getPluginName() + "-" + TestUtil_1.TestUtil.getPluginVersion() + ".tgz";
2021
// CONST VARIABLES
2122
exports.TestAppName = "TestCodePush";
22-
exports.TestNamespace = "com.microsoft.codepush.test";
23+
exports.TestNamespace = "com.testcodepush";
2324
exports.AcquisitionSDKPluginName = "code-push";
2425
exports.templatePath = path.join(__dirname, "../../test/template");
25-
exports.thisPluginPath = TestUtil_1.TestUtil.readMochaCommandLineFlag(PULL_FROM_NPM_FLAG_NAME) ? NPM_PLUGIN_PATH : DEFAULT_PLUGIN_PATH;
26+
exports.thisPluginInstallString = TestUtil_1.TestUtil.readMochaCommandLineFlag(PULL_FROM_NPM_FLAG_NAME) ? `npm install ${NPM_PLUGIN_PATH}` : `npm pack ${DEFAULT_PLUGIN_PATH} && npm install ${DEFAULT_PLUGIN_TGZ_NAME}`;
2627
exports.testRunDirectory = TestUtil_1.TestUtil.readMochaCommandLineOption(TEST_RUN_DIRECTORY_OPTION_NAME, DEFAULT_TEST_RUN_DIRECTORY);
2728
exports.updatesDirectory = TestUtil_1.TestUtil.readMochaCommandLineOption(TEST_UPDATES_DIRECTORY_OPTION_NAME, DEFAULT_UPDATES_DIRECTORY);
2829
exports.onlyRunCoreTests = TestUtil_1.TestUtil.readMochaCommandLineFlag(CORE_TESTS_ONLY_FLAG_NAME);

code-push-plugin-testing-framework/script/testUtil.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ var TestUtil = (function () {
7676
* Returns the name of the plugin that is being tested.
7777
*/
7878
TestUtil.getPluginName = function () {
79-
var packageFile = eval("(" + fs.readFileSync("./package.json", "utf8") + ")");
79+
var packageFile = JSON.parse(fs.readFileSync("./package.json", "utf8"));
8080
return packageFile.name;
8181
};
82+
83+
TestUtil.getPluginVersion = function () {
84+
var packageFile = JSON.parse(fs.readFileSync("./package.json", "utf8"));
85+
return packageFile.version;
86+
};
8287
/**
8388
* Replaces a regex in a file with a given string.
8489
*/

code-push-plugin-testing-framework/typings/code-push-plugin-testing-framework.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ declare module 'code-push-plugin-testing-framework/script/testConfig' {
411411
export const TestNamespace: string;
412412
export const AcquisitionSDKPluginName: string;
413413
export const templatePath: string;
414-
export const thisPluginPath: string;
414+
export const thisPluginInstallString: string;
415415
export const testRunDirectory: string;
416416
export const updatesDirectory: string;
417417
export const onlyRunCoreTests: boolean;

test/test.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class RNAndroid extends Platform.Android implements RNPlatform {
7070
* Returns the path to the binary of the given project on this platform.
7171
*/
7272
getBinaryPath(projectDirectory: string): string {
73-
return path.join(projectDirectory, TestConfig.TestAppName, "android", "app", "build", "outputs", "apk", "app-release-unsigned.apk");
73+
return path.join(projectDirectory, TestConfig.TestAppName, "android", "app", "build", "outputs", "apk", "release", "app-release.apk");
7474
}
7575

7676
/**
@@ -79,35 +79,27 @@ class RNAndroid extends Platform.Android implements RNPlatform {
7979
installPlatform(projectDirectory: string): Q.Promise<void> {
8080
const innerprojectDirectory: string = path.join(projectDirectory, TestConfig.TestAppName);
8181
const gradleContent: string = slash(path.join(innerprojectDirectory, "node_modules", "react-native-code-push", "android", "codepush.gradle"));
82-
82+
8383
//// Set up gradle to build CodePush with the app
8484
// Add CodePush to android/app/build.gradle
8585
const buildGradle = path.join(innerprojectDirectory, "android", "app", "build.gradle");
8686
TestUtil.replaceString(buildGradle,
8787
"apply from: \"../../node_modules/react-native/react.gradle\"",
8888
"apply from: \"../../node_modules/react-native/react.gradle\"\napply from: \"" + gradleContent + "\"");
89-
TestUtil.replaceString(buildGradle,
90-
"compile \"com.facebook.react:react-native:+\"",
91-
"compile \"com.facebook.react:react-native:0.25.+\"");
92-
TestUtil.replaceString(buildGradle,
93-
"// From node_modules",
94-
"\n compile project(':react-native-code-push') // From node_modules");
95-
// Add CodePush to android/settings.gradle
96-
TestUtil.replaceString(path.join(innerprojectDirectory, "android", "settings.gradle"),
97-
"include ':app'",
98-
"include ':app', ':react-native-code-push'\nproject(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')");
99-
89+
10090
//// Set the app version to 1.0.0 instead of 1.0
10191
// Set the app version to 1.0.0 in android/app/build.gradle
10292
TestUtil.replaceString(buildGradle, "versionName \"1.0\"", "versionName \"1.0.0\"");
10393
// Set the app version to 1.0.0 in AndroidManifest.xml
10494
TestUtil.replaceString(path.join(innerprojectDirectory, "android", "app", "src", "main", "AndroidManifest.xml"), "android:versionName=\"1.0\"", "android:versionName=\"1.0.0\"");
10595

106-
//// Replace the MainActivity.java with the correct server url and deployment key
107-
const mainActivity = path.join(innerprojectDirectory, "android", "app", "src", "main", "java", "com", "microsoft", "codepush", "test", "MainActivity.java");
108-
TestUtil.replaceString(mainActivity, TestUtil.CODE_PUSH_TEST_APP_NAME_PLACEHOLDER, TestConfig.TestAppName);
109-
TestUtil.replaceString(mainActivity, TestUtil.SERVER_URL_PLACEHOLDER, this.getServerUrl());
110-
TestUtil.replaceString(mainActivity, TestUtil.ANDROID_KEY_PLACEHOLDER, this.getDefaultDeploymentKey());
96+
//// Replace the MainApplication.java with the correct server url and deployment key
97+
const string = path.join(innerprojectDirectory, "android", "app", "src", "main", "res", "values", "strings.xml");
98+
const AndroidManifest = path.join(innerprojectDirectory, "android", "app", "src", "main", "AndroidManifest.xml");
99+
TestUtil.replaceString(string, TestUtil.SERVER_URL_PLACEHOLDER, this.getServerUrl());
100+
TestUtil.replaceString(string, TestUtil.ANDROID_KEY_PLACEHOLDER, this.getDefaultDeploymentKey());
101+
TestUtil.replaceString(AndroidManifest, "android:allowBackup=\"false\"", "android:allowBackup=\"false\"" + "\n\t" + "android:usesCleartextTraffic=\"true\"");
102+
111103

112104
return Q<void>(null);
113105
}
@@ -128,7 +120,7 @@ class RNAndroid extends Platform.Android implements RNPlatform {
128120
const androidDirectory: string = path.join(projectDirectory, TestConfig.TestAppName, "android");
129121
const apkPath = this.getBinaryPath(projectDirectory);
130122
return TestUtil.getProcessOutput("gradlew assembleRelease --daemon", { cwd: androidDirectory })
131-
.then<void>(TestUtil.getProcessOutput.bind(undefined, "jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android " + apkPath + " androiddebugkey", { cwd: androidDirectory, noLogStdOut: true })).then(() => { return null; });
123+
.then(() => { return null; });
132124
}
133125
}
134126

@@ -306,9 +298,10 @@ class RNProjectManager extends ProjectManager {
306298
}
307299
mkdirp.sync(projectDirectory);
308300

309-
return TestUtil.getProcessOutput("react-native init " + appName + " --package " + appNamespace, { cwd: projectDirectory })
301+
return TestUtil.getProcessOutput("react-native init " + appName, { cwd: projectDirectory })
310302
.then(this.copyTemplate.bind(this, templatePath, projectDirectory))
311-
.then<void>(TestUtil.getProcessOutput.bind(undefined, "npm install " + TestConfig.thisPluginPath, { cwd: path.join(projectDirectory, TestConfig.TestAppName) })).then(() => { return null; });
303+
.then<void>(TestUtil.getProcessOutput.bind(undefined, TestConfig.thisPluginInstallString, { cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
304+
.then(() => { return null; });
312305
}
313306

314307
/** JSON mapping project directories to the current scenario

0 commit comments

Comments
 (0)