Browse Source

fix android e2e and --release flags, closes #1956

Daniel Zlotin 6 years ago
parent
commit
b850e46357

+ 8
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

@@ -6,6 +6,7 @@ import android.provider.Settings;
6 6
 import android.support.test.uiautomator.By;
7 7
 import android.view.KeyEvent;
8 8
 
9
+import org.junit.Assume;
9 10
 import org.junit.Test;
10 11
 
11 12
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
@@ -60,12 +61,15 @@ public class ApplicationLifecycleTest extends BaseTest {
60 61
 
61 62
 	@Test
62 63
 	public void pressingMenuOpensDevMenu() throws Exception {
64
+		Assume.assumeTrue(isDebug());
63 65
 		device().pressKeyCode(KeyEvent.KEYCODE_MENU);
64 66
 		assertExists(By.text("Debug JS Remotely"));
65 67
 	}
66 68
 
67 69
 	@Test
68 70
 	public void pressingRTwiceInSuccessionReloadsReactNative() throws Exception {
71
+		Assume.assumeTrue(isDebug());
72
+
69 73
 		elementByText("PUSH").click();
70 74
 		assertExists(By.text("Pushed Screen"));
71 75
 
@@ -77,6 +81,8 @@ public class ApplicationLifecycleTest extends BaseTest {
77 81
 
78 82
 	@Test
79 83
 	public void pressingRTwiceWithDelayDoesNothing() throws Exception {
84
+		Assume.assumeTrue(isDebug());
85
+
80 86
 		elementByText("PUSH").click();
81 87
 		assertExists(By.text("Pushed Screen"));
82 88
 
@@ -88,6 +94,8 @@ public class ApplicationLifecycleTest extends BaseTest {
88 94
 
89 95
 	@Test
90 96
 	public void sendingReloadBroadcastReloadsReactNative() throws Exception {
97
+		Assume.assumeTrue(isDebug());
98
+
91 99
 		elementByText("PUSH").click();
92 100
 		assertExists(By.text("Pushed Screen"));
93 101
 

+ 7
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/BaseTest.java View File

@@ -1,5 +1,7 @@
1 1
 package com.reactnativenavigation.e2e.androide2e;
2 2
 
3
+import android.content.pm.ApplicationInfo;
4
+import android.content.pm.PackageInfo;
3 5
 import android.graphics.Bitmap;
4 6
 import android.graphics.BitmapFactory;
5 7
 import android.support.test.runner.AndroidJUnit4;
@@ -98,4 +100,9 @@ public abstract class BaseTest {
98 100
 	public void swipeOpenLeftSideMenu() {
99 101
 		device().swipe(5, 152, 500, 152, 15);
100 102
 	}
103
+
104
+	public boolean isDebug() throws Exception {
105
+		PackageInfo packageInfo = getInstrumentation().getTargetContext().getPackageManager().getPackageInfo("com.reactnativenavigation.playground", 0);
106
+		return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
107
+	}
101 108
 }

+ 0
- 1
AndroidE2E/app/src/main/AndroidManifest.xml View File

@@ -12,7 +12,6 @@
12 12
         android:label="@string/app_name"
13 13
         android:supportsRtl="true"
14 14
         android:theme="@style/AppTheme">
15
-
16 15
     </application>
17 16
 
18 17
 </manifest>

+ 1
- 1
AndroidE2E/build.gradle View File

@@ -5,7 +5,7 @@ buildscript {
5 5
         jcenter()
6 6
     }
7 7
     dependencies {
8
-        classpath 'com.android.tools.build:gradle:2.3.2'
8
+        classpath 'com.android.tools.build:gradle:2.3.3'
9 9
 
10 10
         // NOTE: Do not place your application dependencies here; they belong
11 11
         // in the individual module build.gradle files

+ 5
- 5
docs/docs/CONTRIBUTING.md View File

@@ -108,13 +108,13 @@ No PR will be accepted without adequate test coverage.
108 108
 | `npm run clean` | cleans all build directories, stops packager, fixes flakiness by removing watchman cache, etc. |
109 109
 | `npm run start` | starts the react-native packager for local debugging |
110 110
 | `npm run xcode` | for convenience, opens xcode in this project |
111
-| `npm run install-android`  |  builds playground debug/release version and installs on running android devices/emulators. <br> **Options:** `-- release` |
111
+| `npm run install-android`  |  builds playground debug/release version and installs on running android devices/emulators. <br> **Options:** `-- --release` |
112 112
 | `npm run uninstall-android` | uninstalls playground from running android devices/simulators |
113 113
 | `npm run test-js` | runs javascript tests and coverage report |
114 114
 | `npm run test-watch` | runs javascript tests in watch mode (can also use the provided wallaby config) |
115
-| `npm run test-unit-ios` | runs ios unit tests in debug/release <br> **Options:** `-- release` |
116
-| `npm run test-unit-android` | runs android unit tests in debug/release <br> **Options:** `-- release` |
117
-| `npm run test-e2e-ios` | runs the ios e2e suite (with detox) in debug/release |
118
-| `npm run test-e2e-android` | runs the android e2e suite (with uiautomator) in debug/release on running devices/emulators <br> **Options:** `-- [release] [just com.TestClass#testMethod]` |
115
+| `npm run test-unit-ios` | runs ios unit tests in debug/release <br> **Options:** `-- --release` |
116
+| `npm run test-unit-android` | runs android unit tests in debug/release <br> **Options:** `-- --release` |
117
+| `npm run test-e2e-ios` | runs the ios e2e suite (with detox) in debug/release <br> **Options:** `-- --release`|
118
+| `npm run test-e2e-android` | runs the android e2e suite (with uiautomator) in debug/release on running devices/emulators <br> **Options:** `-- [--release] [--just com.TestClass#testMethod]` |
119 119
 | `npm run test-all` | runs all tests in parallel |
120 120
 

+ 1
- 1
scripts/install-android.js View File

@@ -1,7 +1,7 @@
1 1
 const _ = require('lodash');
2 2
 const exec = require('shell-utils').exec;
3 3
 
4
-const release = _.includes(process.argv, 'release');
4
+const release = _.includes(process.argv, '--release');
5 5
 
6 6
 run();
7 7
 

+ 7
- 29
scripts/test.e2e.android.js View File

@@ -2,16 +2,16 @@
2 2
 const _ = require('lodash');
3 3
 const exec = require('shell-utils').exec;
4 4
 
5
-const release = _.includes(process.argv, 'release');
5
+const release = _.includes(process.argv, '--release');
6 6
 
7
-// Run just a single test, e.g. npm test-e2e-android -- just com.MyClass#myMethod
8
-const filter = _(process.argv).dropWhile((a) => a !== 'just').take(2).last();
7
+// Run just a single test, e.g. npm test-e2e-android -- --just com.MyClass#myMethod
8
+const filter = _.chain(process.argv).dropWhile((a) => a !== '--just').take(2).last().value();
9 9
 
10 10
 run();
11 11
 
12 12
 function run() {
13 13
   if (process.env.CI) {
14
-    console.log(`android e2e is disabled on CI`);
14
+    console.log(`android e2e is disabled on CI until Travis will support x86 emulators or we migrate to our own solution`);
15 15
   } else {
16 16
     assertEnv();
17 17
     if (!isDeviceRunning()) {
@@ -38,7 +38,7 @@ function isDeviceRunning() {
38 38
 
39 39
 function startEmulator() {
40 40
   console.log(`Looking for avd...`);
41
-  const avds = exec.execSyncRead(`avdmanager list avd -c`);
41
+  const avds = exec.execSyncRead(`${process.env.ANDROID_HOME}/tools/bin/avdmanager list avd -c`);
42 42
   const avdName = /^.*package\.xml(\S+)$/.exec(avds)[1];
43 43
   if (_.isEmpty(avdName)) {
44 44
     throw new Error(`Launch an android emulator or connect a device`);
@@ -50,30 +50,8 @@ function startEmulator() {
50 50
 
51 51
 function runTests() {
52 52
   exec.execSync(`npm run uninstall-android`);
53
-  exec.execSync(`npm run install-android ${release ? '-- release' : ''}`);
53
+  exec.execSync(`npm run install-android ${release ? '-- --release' : ''}`);
54 54
   const filterParam = filter ? '-Pandroid.testInstrumentationRunnerArguments.class=' + filter : '';
55 55
   exec.execSync(`cd AndroidE2E && ./gradlew ${filterParam} connectedDebugAndroidTest`);
56
+  process.exit(0); // eslint-disable-line
56 57
 }
57
-
58
-// const avdName = 'pixel';
59
-// const sdk = 'android-24';
60
-// const apis = 'default';
61
-// const abi = 'armeabi-v7a';
62
-// const packageName = `system-images;${sdk};${apis};${abi}`;
63
-
64
-// function installEmulator() {
65
-//   exec.execSync(`sdkmanager "emulator"`);
66
-//   exec.execSync(`sdkmanager "${packageName}"`);
67
-//   exec.execSync(`echo no | avdmanager create avd --force --name "${avdName}" --abi "${apis}/${abi}" --package "${packageName}" --device "pixel"`);
68
-//   exec.execSync(`avdmanager list avd`);
69
-// }
70
-
71
-// function launchEmulator() {
72
-//   console.log(`Launching Android Emulator`);
73
-//   exec.execSync(`cd $ANDROID_HOME/tools && ./emulator -skin 1080x1920 -gpu host -no-audio @${avdName}`);
74
-//   exec.execSync(`./scripts/waitForAndroidEmulator.sh`);
75
-// }
76
-
77
-// function killEmulators() {
78
-//   exec.execSync(`adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done`);
79
-// }

+ 1
- 1
scripts/test.e2e.ios.js View File

@@ -1,7 +1,7 @@
1 1
 const _ = require('lodash');
2 2
 const exec = require('shell-utils').exec;
3 3
 
4
-const release = _.includes(process.argv, 'release');
4
+const release = _.includes(process.argv, '--release');
5 5
 
6 6
 function buildProjForDetox() {
7 7
   const scheme = release ? `playground_release` : `playground`;

+ 1
- 1
scripts/test.unit.android.js View File

@@ -1,7 +1,7 @@
1 1
 const _ = require('lodash');
2 2
 const exec = require('shell-utils').exec;
3 3
 
4
-const release = _.includes(process.argv, 'release');
4
+const release = _.includes(process.argv, '--release');
5 5
 
6 6
 run();
7 7
 

+ 1
- 1
scripts/test.unit.ios.js View File

@@ -1,7 +1,7 @@
1 1
 const _ = require('lodash');
2 2
 const exec = require('shell-utils').exec;
3 3
 
4
-const release = _.includes(process.argv, 'release');
4
+const release = _.includes(process.argv, '--release');
5 5
 
6 6
 function run() {
7 7
   const conf = release ? `Release` : `Debug`;

+ 4
- 4
scripts/travis.sh View File

@@ -22,8 +22,8 @@ run_f () {
22 22
 run_f "npm install"
23 23
 run_f "npm run clean"
24 24
 run_f "npm run test-js"
25
-run_f "npm run test-unit-android -- release"
26
-run_f "npm run test-unit-ios -- release"
27
-run_f "npm run test-e2e-android -- release"
28
-run_f "npm run test-e2e-ios -- release"
25
+run_f "npm run test-unit-android -- --release"
26
+run_f "npm run test-unit-ios -- --release"
27
+run_f "npm run test-e2e-android -- --release"
28
+run_f "npm run test-e2e-ios -- --release"
29 29
 run_f "npm run release"