Daniel Zlotin 7 years ago
parent
commit
db04a52e4a
3 changed files with 43 additions and 6 deletions
  1. 2
    0
      .travis.yml
  2. 4
    0
      scripts/env/installAppleSimUtils.sh
  3. 37
    6
      scripts/test.e2e.android.js

+ 2
- 0
.travis.yml View File

26
   - source ./scripts/env/installNode.sh
26
   - source ./scripts/env/installNode.sh
27
         # android sdk:
27
         # android sdk:
28
   - source ./scripts/env/installAndroidSDK.sh
28
   - source ./scripts/env/installAndroidSDK.sh
29
+        # AppleSimUtils
30
+  - source ./scripts/env/installAppleSimUtils.sh
29
 
31
 
30
 script:
32
 script:
31
   - set -e
33
   - set -e

+ 4
- 0
scripts/env/installAppleSimUtils.sh View File

1
+#!/bin/bash -e
2
+
3
+brew tap wix/brew
4
+brew install --HEAD applesimutils

+ 37
- 6
scripts/test.e2e.android.js View File

2
 const _ = require('lodash');
2
 const _ = require('lodash');
3
 const exec = require('shell-utils').exec;
3
 const exec = require('shell-utils').exec;
4
 
4
 
5
-// const avdName = 'pixel';
6
-// const sdk = 'android-24';
7
-// const apis = 'default';
8
-// const abi = 'armeabi-v7a';
9
-// const packageName = `system-images;${sdk};${apis};${abi}`;
10
-
11
 const release = _.includes(process.argv, 'release');
5
 const release = _.includes(process.argv, 'release');
12
 
6
 
13
 // Run just a single test, e.g. npm test-e2e-android -- just com.MyClass#myMethod
7
 // Run just a single test, e.g. npm test-e2e-android -- just com.MyClass#myMethod
19
   if (process.env.CI) {
13
   if (process.env.CI) {
20
     console.log(`android e2e is disabled on CI`);
14
     console.log(`android e2e is disabled on CI`);
21
   } else {
15
   } else {
16
+    assertEnv();
17
+    if (!isDeviceRunning()) {
18
+      startEmulator();
19
+    }
22
     runTests();
20
     runTests();
23
   }
21
   }
24
 }
22
 }
25
 
23
 
24
+function assertEnv() {
25
+  if (_.isEmpty(process.env.ANDROID_HOME)) {
26
+    throw new Error(`$ANDROID_HOME is not defined`);
27
+  }
28
+}
29
+
30
+function isDeviceRunning() {
31
+  try {
32
+    const response = exec.execSyncRead(`adb -e shell getprop init.svc.bootanim 2>&1`);
33
+    return _.isEqual(response, `stopped`);
34
+  } catch (err) {
35
+    return false;
36
+  }
37
+}
38
+
39
+function startEmulator() {
40
+  console.log(`Looking for avd...`);
41
+  const avds = exec.execSyncRead(`avdmanager list avd -c`);
42
+  const avdName = /^.*package\.xml(\S+)$/.exec(avds)[1];
43
+  if (_.isEmpty(avdName)) {
44
+    throw new Error(`Launch an android emulator or connect a device`);
45
+  }
46
+  console.log(`found avd name: ${avdName}, Launching...`);
47
+  exec.execAsyncSilent(`${process.env.ANDROID_HOME}/tools/emulator -gpu host -no-audio @${avdName}`);
48
+  exec.execSync(`./scripts/waitForAndroidEmulator.sh`);
49
+}
50
+
26
 function runTests() {
51
 function runTests() {
27
   exec.execSync(`npm run uninstall-android`);
52
   exec.execSync(`npm run uninstall-android`);
28
   exec.execSync(`npm run install-android ${release ? '-- release' : ''}`);
53
   exec.execSync(`npm run install-android ${release ? '-- release' : ''}`);
30
   exec.execSync(`cd AndroidE2E && ./gradlew ${filterParam} connectedDebugAndroidTest`);
55
   exec.execSync(`cd AndroidE2E && ./gradlew ${filterParam} connectedDebugAndroidTest`);
31
 }
56
 }
32
 
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
+
33
 // function installEmulator() {
64
 // function installEmulator() {
34
 //   exec.execSync(`sdkmanager "emulator"`);
65
 //   exec.execSync(`sdkmanager "emulator"`);
35
 //   exec.execSync(`sdkmanager "${packageName}"`);
66
 //   exec.execSync(`sdkmanager "${packageName}"`);