Skip to content

Commit 5b06a3c

Browse files
author
Brandon Sneed
committed
Merge branch 'master' into bsneed/context-fixes
2 parents 6795a6a + d72f747 commit 5b06a3c

File tree

23 files changed

+262
-135
lines changed

23 files changed

+262
-135
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/core/android/build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33

4+
def defaultKotlinVersion = '1.3.21'
5+
def safeExtGet(prop, fallback) {
6+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
7+
}
8+
49
buildscript {
510
repositories {
611
jcenter()
712
maven { url 'https://maven.google.com' }
813
}
914
dependencies {
1015
classpath 'com.android.tools.build:gradle:3.1.4'
11-
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21'
16+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet("kotlinVersion", defaultKotlinVersion)}"
1217
}
1318
}
1419

15-
def safeExtGet(prop, fallback) {
16-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
17-
}
18-
1920
android {
2021
compileSdkVersion safeExtGet('compileSdkVersion', 26)
2122
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')
@@ -41,5 +42,5 @@ dependencies {
4142
api 'com.segment.analytics.android:analytics:4.5.0-beta.0'
4243

4344
api 'com.facebook.react:react-native:+'
44-
api 'org.jetbrains.kotlin:kotlin-stdlib:1.3.21'
45+
api "org.jetbrains.kotlin:kotlin-stdlib:${safeExtGet("kotlinVersion", defaultKotlinVersion)}"
4546
}

packages/core/android/src/main/java/com/segment/analytics/reactnative/core/RNAnalyticsModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class RNAnalyticsModule(context: ReactApplicationContext): ReactContextBaseJavaM
148148
Analytics.setSingletonInstance(
149149
RNAnalytics.buildWithIntegrations(builder)
150150
)
151+
} catch(e2: IllegalStateException) {
152+
// pass if the error is due to calling setSingletonInstance multiple times
153+
154+
// if you created singleton in native code already,
155+
// you need to promise.resolve for RN to properly operate
151156
} catch(e: Exception) {
152157
return promise.reject("E_SEGMENT_ERROR", e)
153158
}

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/src/gen-integrations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ async function prepareiOS({
6969
const xcodeProject = 'ios/RNAnalyticsIntegration.xcodeproj'
7070
const targetXcodeProject = `ios/${nativeModule}.xcodeproj`
7171
const pod_name = `RNAnalyticsIntegration-${slug('-')}`
72+
const framework_name = `Segment_${slug()}`
7273
const {
7374
pod: {
7475
name: pod_dependency = `Segment-${slug()}`,
@@ -79,7 +80,7 @@ async function prepareiOS({
7980
const classSlug = `${prefix}${slug()}IntegrationFactory`
8081
const {
8182
className = classSlug,
82-
framework = pod_dependency,
83+
framework = framework_name,
8384
header = classSlug
8485
} = ios
8586

packages/integrations/template/Pod.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ Pod::Spec.new do |s|
2525
s.dependency '{{{pod_dependency}}}'{{#pod_version}}, '~> {{{pod_version}}}'{{/pod_version}}
2626
s.dependency 'Analytics'
2727
s.dependency 'React'
28+
s.dependency 'RNAnalytics'
2829
end

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.

0 commit comments

Comments
 (0)