Skip to content

Commit d72f747

Browse files
author
Kadi Kraman
authored
chore(e2e): update detox and android configuration (#78)
chore(e2e): add release configuration for android chore(e2e): update test dependencies chore(e2e): install API 28 Android emulator chore(e2e): install Android emulator chore(e2e): use rn community orb chore(e2e): remove duplicate version chore(e2e): revert ci config chore(e2e): add local e2e testing instructions chore(e2e): disable android integrations chore(e2e): run all e2e tests chore(e2e): run all e2e tests chore(e2e): run dev android build chore(e2e): update android config chore(e2e): update android config chore(e2e): bail out of e2e tests when no E2E_TOKEN is present chore(e2e): fix android build
1 parent 3c29a88 commit d72f747

File tree

19 files changed

+247
-128
lines changed

19 files changed

+247
-128
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
test-ios-vanilla:
9494
<<: *job
9595
macos:
96-
xcode: "9.4.0"
96+
xcode: '10.0.0'
9797
steps:
9898
- checkout
9999
# macOS VMs doesn't support Docker based caches
@@ -108,7 +108,7 @@ jobs:
108108
test-ios-cocoapods:
109109
<<: *job
110110
macos:
111-
xcode: "9.4.0"
111+
xcode: '10.0.0'
112112
steps:
113113
- checkout
114114
# macOS VMs doesn't support Docker based caches
@@ -171,19 +171,19 @@ workflows:
171171
only: /.*/
172172
- test-android:
173173
requires:
174-
- build-test-app
174+
- build-test-app
175175
filters:
176176
tags:
177177
only: /.*/
178178
- test-ios-vanilla:
179179
requires:
180-
- build-test-app
180+
- build-test-app
181181
filters:
182182
tags:
183183
only: /.*/
184184
- test-ios-cocoapods:
185185
requires:
186-
- build-test-app
186+
- build-test-app
187187
filters:
188188
tags:
189189
only: /.*/

CONTRIBUTING.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,59 @@ $ yarn
4949
$ yarn test
5050
```
5151

52+
### End-to-end testing
53+
54+
End-to-end testing is done using [Detox](https://github.com/wix/Detox).
55+
56+
These tests are primarily built to be run on CI. The following instructions describe how to run them locally.
57+
58+
Tested on Mac only.
59+
60+
#### iOS
61+
62+
First, install your dependencies as described in [Step 1: Install dependencies](https://github.com/wix/Detox/blob/master/docs/Introduction.GettingStarted.md#step-1-install-dependencies).
63+
64+
```bash
65+
yarn # install project dependencies
66+
yarn build # build project and integrations
67+
cd packages/test-app
68+
yarn test:ios:cocoapods # or test:ios:vanilla
69+
```
70+
71+
For subsequent runs, you may need to do `rm -rf project && ./generate.sh` before running the test command.
72+
73+
### Android
74+
75+
Set up an Android emulator locally. The easiest way to do this is to install and launch Android Studio, and [manage your virtual devices](https://developer.android.com/studio/run/managing-avds) through the UI.
76+
77+
Check you have at least one emulator installed with `emulator -list-avds`. Now open `./packages/test-app/package.json` and ensure that the `name` under `"android.emu.release"` is one of the emulators in your list (change it if not, but do not commit this change).
78+
79+
```bash
80+
yarn # install project dependencies
81+
yarn build # build project and integrations
82+
cd packages/test-app
83+
SEGMENT_WRITE_TOKEN=test yarn test:android
84+
```
85+
86+
**Note:** A non-empty value of SEGMENT_WRITE_TOKEN is required for Android (but not iOS), because the native library will do a not null check for it and your application will crash.
87+
88+
**Note:** you can also run the emulator in debug mode, but you'll have to start the packager manually. Assuming you've already installed dependencies and built the project:
89+
90+
Build the android project and start the packager:
91+
92+
```bash
93+
cd packages/test-app
94+
SEGMENT_WRITE_TOKEN=test detox build -c android.emu.debug
95+
cd project
96+
yarn start
97+
```
98+
99+
In a new terminal window, run:
100+
101+
```bash
102+
detox test -c android.emu.debug
103+
```
104+
52105
### Architecture
53106

54107
- `packages/core`: the `@segment/analytics-react-native` module

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ await analytics.setup('writeKey', {
166166
| [Firebase](https://www.npmjs.com/package/@segment/analytics-react-native-firebase) | :white_check_mark: | :white_check_mark: | `@segment/analytics-react-native-firebase` |
167167
| [Flurry](https://www.npmjs.com/package/@segment/analytics-react-native-flurry) | :white_check_mark: | :white_check_mark: | `@segment/analytics-react-native-flurry` |
168168
| [Google Analytics](https://www.npmjs.com/package/@segment/analytics-react-native-google-analytics) | :white_check_mark: | :white_check_mark: | `@segment/analytics-react-native-google-analytics` |
169-
| [Intercom](https://www.npmjs.com/package/@segment/analytics-react-native-intercom) | :white_check_mark: | :white_check_mark: | `@segment/analytics-react-native-intercom` |
169+
| [Intercom](https://www.npmjs.com/package/@segment/analytics-react-native-intercom-ios) | :white_check_mark: | :x: | `@segment/analytics-react-native-intercom-ios` |
170170
| [Localytics](https://www.npmjs.com/package/@segment/analytics-react-native-localytics) | :white_check_mark: | :white_check_mark: | `@segment/analytics-react-native-localytics` |
171171
| [Mixpanel](https://www.npmjs.com/package/@segment/analytics-react-native-mixpanel) | :white_check_mark: | :white_check_mark: | `@segment/analytics-react-native-mixpanel` |
172-
| [Quantcast](https://www.npmjs.com/package/@segment/analytics-react-native-quantcast-android) | :x: | :white_check_mark: | `@segment/analytics-react-native-quantcast-android` |
173172
| [Taplytics](https://www.npmjs.com/package/@segment/analytics-react-native-taplytics-ios) | :white_check_mark: | :x: | `@segment/analytics-react-native-taplytics-ios` |
174173
| [Tapstream](https://www.npmjs.com/package/@segment/analytics-react-native-tapstream-android) | :x: | :white_check_mark: | `@segment/analytics-react-native-tapstream-android` |
175174

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"npm-run-all": "^4.1.3",
7171
"prettier": "^1.14.2",
7272
"react": "16.8.3",
73-
"react-native": "0.59.2",
73+
"react-native": "0.59.9",
7474
"rimraf": "^2.6.2"
7575
}
7676
}

packages/integrations/integrations.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
ios:
2323
# Only compatible 3.0.x
2424
disabled: true
25+
android:
26+
disabled: true
2527

2628
- name: Intercom
2729
ios:
2830
pod:
2931
version: 1.0.0-beta
32+
android:
33+
disabled: true
3034

3135
- name: Tapstream
3236
ios:

packages/integrations/template/android/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ android {
2626
versionName '1.0'
2727

2828
}
29+
packagingOptions {
30+
pickFirst "META-INF/*"
31+
}
2932
}
3033

3134
repositories {

packages/test-app/e2e/main.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ it('sends events and does not crash', async () => {
1414
await sleep(5 * 1000)
1515
})
1616

17-
if (CIRCLE_WORKFLOW_ID) {
17+
if (CIRCLE_WORKFLOW_ID && E2E_TOKEN) {
1818
it('sends events to the webhook', async () => {
1919
await element(by.text('Launch test suite')).tap()
2020
await element(by.text('Flush')).tap()

packages/test-app/package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
"test:ios:cocoapods": "COCOAPODS=yes ./test_ios.sh",
1313
"test:ios:vanilla": "COCOAPODS=no ./test_ios.sh",
1414
"test:android": "./test_android.sh",
15-
"test": "run-s test:{ios,android}",
16-
"detox:build": "detox build",
17-
"detox:test": "detox test"
15+
"test": "run-s test:{ios,android}"
1816
},
1917
"devDependencies": {
2018
"jest": "^24.5.0",
2119
"react-native-cli": "^2.0.1"
2220
},
2321
"dependencies": {
24-
"detox": "^12.1.1",
22+
"detox": "^12.11.0",
2523
"isomorphic-fetch": "^2.2.1"
2624
},
2725
"detox": {
@@ -41,11 +39,17 @@
4139
"type": "ios.simulator",
4240
"name": "iPhone X"
4341
},
44-
"android": {
42+
"android.emu.release": {
43+
"binaryPath": "project/android/app/build/outputs/apk/release/app-release.apk",
44+
"build": "cd project/android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release",
45+
"type": "android.emulator",
46+
"name": "Nexus_5X_API_28"
47+
},
48+
"android.emu.debug": {
4549
"binaryPath": "project/android/app/build/outputs/apk/debug/app-debug.apk",
4650
"build": "cd project/android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug",
4751
"type": "android.emulator",
48-
"name": "Nexus_5X_API_27"
52+
"name": "Nexus_5X_API_28"
4953
}
5054
}
5155
}

packages/test-app/seed/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ yarn-error.log
3939
# BUCK
4040
buck-out/
4141
\.buckd/
42-
*.keystore
4342

4443
# fastlane
4544
#

packages/test-app/seed/__tests__/App-test.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Binary file not shown.

packages/test-app/seed/android/app/build.gradle

Lines changed: 23 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,6 @@ apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
44

5-
/**
6-
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7-
* and bundleReleaseJsAndAssets).
8-
* These basically call `react-native bundle` with the correct arguments during the Android build
9-
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10-
* bundle directly from the development server. Below you can see all the possible configurations
11-
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12-
* `apply from: "../../node_modules/react-native/react.gradle"` line.
13-
*
14-
* project.ext.react = [
15-
* // the name of the generated asset file containing your JS bundle
16-
* bundleAssetName: "index.android.bundle",
17-
*
18-
* // the entry file for bundle generation
19-
* entryFile: "index.android.js",
20-
*
21-
* // whether to bundle JS and assets in debug mode
22-
* bundleInDebug: false,
23-
*
24-
* // whether to bundle JS and assets in release mode
25-
* bundleInRelease: true,
26-
*
27-
* // whether to bundle JS and assets in another build variant (if configured).
28-
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29-
* // The configuration property can be in the following formats
30-
* // 'bundleIn${productFlavor}${buildType}'
31-
* // 'bundleIn${buildType}'
32-
* // bundleInFreeDebug: true,
33-
* // bundleInPaidRelease: true,
34-
* // bundleInBeta: true,
35-
*
36-
* // whether to disable dev mode in custom build variants (by default only disabled in release)
37-
* // for example: to disable dev mode in the staging build type (if configured)
38-
* devDisabledInStaging: true,
39-
* // The configuration property can be in the following formats
40-
* // 'devDisabledIn${productFlavor}${buildType}'
41-
* // 'devDisabledIn${buildType}'
42-
*
43-
* // the root of your project, i.e. where "package.json" lives
44-
* root: "../../",
45-
*
46-
* // where to put the JS bundle asset in debug mode
47-
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
48-
*
49-
* // where to put the JS bundle asset in release mode
50-
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
51-
*
52-
* // where to put drawable resources / React Native assets, e.g. the ones you use via
53-
* // require('./image.png')), in debug mode
54-
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
55-
*
56-
* // where to put drawable resources / React Native assets, e.g. the ones you use via
57-
* // require('./image.png')), in release mode
58-
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
59-
*
60-
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
61-
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
62-
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
63-
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
64-
* // for example, you might want to remove it from here.
65-
* inputExcludes: ["android/**", "ios/**"],
66-
*
67-
* // override which node gets called and with what additional arguments
68-
* nodeExecutableAndArgs: ["node"],
69-
*
70-
* // supply additional arguments to the packager
71-
* extraPackagerArgs: []
72-
* ]
73-
*/
74-
755
project.ext.react = [
766
entryFile: "index.js"
777
]
@@ -96,6 +26,16 @@ def enableProguardInReleaseBuilds = false
9626
android {
9727
compileSdkVersion rootProject.ext.compileSdkVersion
9828

29+
signingConfigs {
30+
31+
release {
32+
storeFile file("android.keystore")
33+
storePassword "notSecret"
34+
keyAlias "segmentTesting"
35+
keyPassword "notSecret"
36+
}
37+
}
38+
9939
packagingOptions {
10040
pickFirst "META-INF/*"
10141
}
@@ -111,6 +51,9 @@ android {
11151
targetSdkVersion rootProject.ext.targetSdkVersion
11252
versionCode 1
11353
versionName "1.0"
54+
testBuildType System.getProperty("testBuildType", "debug") // This will later be used to control the test apk build type
55+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
56+
multiDexEnabled true
11457
}
11558
splits {
11659
abi {
@@ -122,8 +65,10 @@ android {
12265
}
12366
buildTypes {
12467
release {
68+
signingConfig signingConfigs.release
12569
minifyEnabled enableProguardInReleaseBuilds
12670
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
71+
proguardFile "${rootProject.projectDir}/../../node_modules/detox/android/detox/proguard-rules-app.pro"
12772
}
12873
}
12974
// applicationVariants are e.g. debug, release
@@ -139,17 +84,24 @@ android {
13984
}
14085
}
14186
}
87+
lintOptions {
88+
checkReleaseBuilds false
89+
}
14290
}
14391

14492
dependencies {
14593
implementation fileTree(dir: "libs", include: ["*.jar"])
14694
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
14795
implementation "com.facebook.react:react-native:+" // From node_modules
96+
implementation "com.android.support:design:27.1.0"
97+
implementation 'com.android.support:multidex:1.0.3'
98+
androidTestImplementation("com.wix:detox:+") { transitive = true }
99+
androidTestImplementation "junit:junit:4.12"
148100
}
149101

150102
// Run this once to be able to run the application with BUCK
151103
// puts all compile dependencies into folder libs for BUCK to use
152104
task copyDownloadableDepsToLibs(type: Copy) {
153105
from configurations.compile
154-
into 'libs'
106+
into "libs"
155107
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.testapp;
2+
3+
import com.wix.detox.Detox;
4+
5+
import org.junit.Rule;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
9+
import androidx.test.ext.junit.runners.AndroidJUnit4;
10+
import androidx.test.filters.LargeTest;
11+
import androidx.test.rule.ActivityTestRule;
12+
13+
@RunWith(AndroidJUnit4.class)
14+
@LargeTest
15+
public class DetoxTest {
16+
17+
@Rule
18+
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
19+
20+
@Test
21+
public void runDetoxTests() {
22+
Detox.runTests(mActivityRule);
23+
}
24+
}

0 commit comments

Comments
 (0)