Skip to content

Commit 6e73fd4

Browse files
authored
Run Detox Android on CircleCI (#465)
* Run Detox Android on CircleCI * Add `0.68` to the matrix * Remove unnecessary requires * Use `android_emulator_start` command from `react-native` orb * Use `android` orb instead * List available SDKs * Use `android/save-gradle-cache` and use the right system image * Add `post-emulator-launch-assemble-command` * Setup Detox for React Native 0.68 * Configure Blob
1 parent ec4f44d commit 6e73fd4

File tree

10 files changed

+109
-10
lines changed

10 files changed

+109
-10
lines changed

.circleci/config.yml

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ aliases:
88
orbs:
99
node: circleci/[email protected]
1010
browser-tools: circleci/[email protected]
11+
android: circleci/[email protected]
1112

1213
executors:
1314
node:
@@ -217,6 +218,36 @@ jobs:
217218
name: Run Detox on iOS
218219
command: yarn e2e:ios
219220
- save-cache-detox-app
221+
test-android:
222+
parameters:
223+
react-native-version:
224+
type: string
225+
executor:
226+
name: android/android-machine
227+
resource-class: large
228+
tag: 2023.11.1
229+
working_directory: ~/react-native-url-polyfill/platforms/react-native/<< parameters.react-native-version >>
230+
steps:
231+
- attach-workspace
232+
- install-node
233+
- install-yarn-dependencies
234+
- run:
235+
name: List available SDKs
236+
command: sdkmanager --list
237+
- android/create-avd:
238+
avd-name: TestingAVD
239+
install: true
240+
system-image: system-images;android-34;default;x86_64
241+
- android/start-emulator:
242+
avd-name: TestingAVD
243+
no-window: true
244+
post-emulator-launch-assemble-command: ''
245+
restore-gradle-cache-prefix: v1a
246+
- run:
247+
name: Run Detox
248+
command: yarn e2e:android
249+
- android/save-gradle-cache:
250+
cache-prefix: v1a
220251
test-hermes-android:
221252
parameters:
222253
react-native-version:
@@ -302,16 +333,10 @@ workflows:
302333
requires:
303334
- lint
304335
- test-js
305-
- test-hermes-ios:
306-
matrix:
307-
parameters:
308-
react-native-version: ['0.68']
309-
requires:
310-
- test-ios-<< matrix.react-native-version >>
311-
- test-hermes-android:
336+
- test-android:
312337
matrix:
313338
parameters:
314-
react-native-version: ['0.68']
339+
react-native-version: ['0.68', '0.72']
315340
requires:
316341
- lint
317342
- test-js
@@ -322,3 +347,15 @@ workflows:
322347
# requires:
323348
# - lint
324349
# - test-js
350+
- test-hermes-ios:
351+
matrix:
352+
parameters:
353+
react-native-version: ['0.68']
354+
requires:
355+
- test-ios-<< matrix.react-native-version >>
356+
- test-hermes-android:
357+
matrix:
358+
parameters:
359+
react-native-version: ['0.68']
360+
requires:
361+
- test-android-<< matrix.react-native-version >>

platforms/detox/.detoxrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252
emulator: {
5353
type: 'android.emulator',
5454
device: {
55-
avdName: 'Pixel_3a_API_34_extension_level_7_arm64-v8a',
55+
avdName: 'TestingAVD',
5656
},
5757
},
5858
},

platforms/react-native/0.68/android/app/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ android {
170170
}
171171
}
172172
}
173+
174+
testBuildType System.getProperty('testBuildType', 'debug')
175+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
173176
}
174177

175178
if (isNewArchitectureEnabled()) {
@@ -260,6 +263,9 @@ android {
260263
}
261264

262265
dependencies {
266+
androidTestImplementation('com.wix:detox:+')
267+
implementation 'androidx.appcompat:appcompat:1.1.0'
268+
263269
implementation fileTree(dir: "libs", include: ["*.jar"])
264270

265271
//noinspection GradleDynamicVersion
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.detox;
2+
3+
import com.wix.detox.Detox;
4+
import com.wix.detox.config.DetoxConfig;
5+
6+
import org.junit.Rule;
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import androidx.test.ext.junit.runners.AndroidJUnit4;
11+
import androidx.test.filters.LargeTest;
12+
import androidx.test.rule.ActivityTestRule;
13+
14+
@RunWith(AndroidJUnit4.class)
15+
@LargeTest
16+
public class DetoxTest {
17+
@Rule
18+
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
19+
20+
@Test
21+
public void runDetoxTests() {
22+
DetoxConfig detoxConfig = new DetoxConfig();
23+
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90;
24+
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60;
25+
detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60);
26+
27+
Detox.runTests(mActivityRule, detoxConfig);
28+
}
29+
}

platforms/react-native/0.68/android/app/src/debug/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
tools:targetApi="28"
1010
tools:ignore="GoogleAppIndexingWarning">
1111
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
12+
<provider
13+
android:name="com.facebook.react.modules.blob.BlobProvider"
14+
android:authorities="@string/blob_provider_authority"
15+
android:exported="false"
16+
/>
1217
</application>
1318
</manifest>

platforms/react-native/0.68/android/app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
android:icon="@mipmap/ic_launcher"
1010
android:roundIcon="@mipmap/ic_launcher_round"
1111
android:allowBackup="false"
12-
android:theme="@style/AppTheme">
12+
android:theme="@style/AppTheme"
13+
android:networkSecurityConfig="@xml/network_security_config">
1314
<activity
1415
android:name=".MainActivity"
1516
android:label="@string/app_name"
@@ -22,5 +23,10 @@
2223
<category android:name="android.intent.category.LAUNCHER" />
2324
</intent-filter>
2425
</activity>
26+
<provider
27+
android:name="com.facebook.react.modules.blob.BlobProvider"
28+
android:authorities="@string/blob_provider_authority"
29+
android:exported="false"
30+
/>
2531
</application>
2632
</manifest>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">Detox</string>
3+
<string name="blob_provider_authority">com.detox.blobs</string>
34
</resources>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<domain-config cleartextTrafficPermitted="true">
4+
<domain includeSubdomains="true">10.0.2.2</domain>
5+
<domain includeSubdomains="true">localhost</domain>
6+
</domain-config>
7+
</network-security-config>

platforms/react-native/0.68/android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
44

55
buildscript {
66
ext {
7+
kotlinVersion = '1.6.21'
78
buildToolsVersion = "31.0.0"
89
minSdkVersion = 21
910
compileSdkVersion = 31
@@ -25,6 +26,7 @@ buildscript {
2526
classpath("com.android.tools.build:gradle:7.0.4")
2627
classpath("com.facebook.react:react-native-gradle-plugin")
2728
classpath("de.undercouch:gradle-download-task:4.1.2")
29+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
2830
// NOTE: Do not place your application dependencies here; they belong
2931
// in the individual module build.gradle files
3032
}
@@ -47,6 +49,9 @@ allprojects {
4749
excludeGroup "com.facebook.react"
4850
}
4951
}
52+
maven {
53+
url "$rootDir/../node_modules/detox/Detox-android"
54+
}
5055
google()
5156
maven { url 'https://www.jitpack.io' }
5257
}

platforms/react-native/0.68/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"build:ios": "detox build --configuration ios.sim.release",
1212
"test:ios": "detox test --configuration ios.sim.release --cleanup",
1313
"e2e:ios": "yarn build:ios && yarn test:ios",
14+
"build:android": "detox build --configuration android.emu.release",
15+
"test:android": "detox test --configuration android.emu.release",
16+
"e2e:android": "yarn build:android && yarn test:android",
1417
"postinstall": "patch-package"
1518
},
1619
"dependencies": {

0 commit comments

Comments
 (0)