Skip to content

Commit a4f3ed4

Browse files
troZeePiotr Trocki
andauthored
chore: add detox to the project (#320)
* wip * fix debug ios * fix android * fix ios and android * add e2e_release_ios * fix lint * fix circleCI script * fix detox script * remove orb * fix config * add orb * change dir * ls * working_directory * fix config * detox clean-framework-cache && detox build-framework-cache * configure android * fix android * change avd name * uncomment jobs * write 1 test case * add typescript to detox * fix lint * moar tests * moar test * test ios * test android * android-29 * add butler * hide imageview * remove image * fix artifact path Co-authored-by: Piotr Trocki <[email protected]>
1 parent 4295932 commit a4f3ed4

28 files changed

+3046
-394
lines changed

.circleci/config.yml

Lines changed: 102 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
# Orb support is from version >= 2.1
21
version: 2.1
32

4-
# Make sure you use the latest version of the Orb!
53
orbs:
64
rn: react-native-community/[email protected]
75

8-
# Custom jobs which are not part of the Orb
9-
jobs:
10-
checkout_code:
11-
executor: rn/linux_js
6+
executors:
7+
default:
8+
docker:
9+
- image: circleci/node:10
10+
working_directory: ~/project
11+
12+
commands:
13+
attach_project:
1214
steps:
13-
- checkout
14-
- persist_to_workspace:
15-
root: .
16-
paths:
17-
- .
15+
- attach_workspace:
16+
at: ~/project
17+
18+
jobs:
1819
install-dependencies:
19-
executor: rn/linux_js
20+
executor: default
2021
steps:
21-
- attach_workspace:
22-
at: .
22+
- checkout
23+
- attach_project
2324
- restore_cache:
2425
keys:
2526
- dependencies-{{ checksum "package.json" }}
@@ -35,49 +36,106 @@ jobs:
3536
yarn install --frozen-lockfile
3637
- save_cache:
3738
key: dependencies-{{ checksum "package.json" }}
38-
paths:
39-
- node_modules
39+
paths: node_modules
4040
- save_cache:
4141
key: dependencies-example-{{ checksum "example/package.json" }}
42-
paths:
43-
- example/node_modules
42+
paths: example/node_modules
4443
- persist_to_workspace:
4544
root: .
46-
paths:
47-
- .
48-
analyse_js:
49-
executor: rn/linux_js
45+
paths: .
46+
47+
lint:
48+
executor: default
49+
steps:
50+
- attach_project
51+
- run:
52+
name: Lint files
53+
command: |
54+
yarn lint
55+
typescript:
56+
executor: default
57+
steps:
58+
- attach_project
59+
- run:
60+
name: Typecheck files
61+
command: |
62+
yarn typescript
63+
e2e_release_ios:
64+
executor:
65+
name: rn/macos
66+
xcode_version: '11.4.0'
5067
steps:
5168
- attach_workspace:
5269
at: .
53-
- rn/yarn_install
70+
- rn/setup_macos_executor:
71+
node_version: '12.10.0'
72+
- rn/ios_simulator_start:
73+
device: 'iPhone 11'
74+
- rn/pod_install:
75+
pod_install_directory: 'example/ios'
76+
- run:
77+
command: yarn --cwd example detox:ios:build:release
78+
name: build for detox
5479
- run:
55-
name: Run ESLint
56-
command: yarn lint
80+
command: detox clean-framework-cache && detox build-framework-cache && yarn --cwd example detox:ios:test:release
81+
name: test detox
82+
- store_artifacts:
83+
path: ./example/artifacts
84+
e2e_release_android:
85+
# we need to use mac to run emulator with acceleration
86+
# see https://support.circleci.com/hc/en-us/articles/360000028928-Testing-with-Android-emulator-on-CircleCI-2-0
87+
executor:
88+
name: rn/macos
89+
xcode_version: '11.4.0'
90+
steps:
91+
- attach_workspace:
92+
at: .
93+
- rn/setup_macos_executor:
94+
node_version: '12.10.0'
95+
- rn/android_emulator_start:
96+
logcat_grep: 'com.example.reactnativepagerview'
97+
platform_version: 'android-29'
5798
- run:
58-
name: Typescript
59-
command: yarn typescript
99+
command: yarn --cwd example detox:android:build:release
100+
name: build for detox
101+
- run:
102+
command: yarn --cwd example detox:android:test:release
103+
name: test detox
104+
- store_artifacts:
105+
path: ./example/artifacts
106+
unit-tests:
107+
executor: default
108+
steps:
109+
- attach_project
110+
- run:
111+
name: Run unit tests
112+
command: |
113+
yarn test --coverage
114+
- store_artifacts:
115+
path: coverage
116+
destination: coverage
60117

118+
build-package:
119+
executor: default
120+
steps:
121+
- attach_project
122+
- run:
123+
name: Build package
124+
command: |
125+
yarn prepare
61126
workflows:
62-
test:
127+
build-and-test:
63128
jobs:
64-
# Checkout the code and persist to the Workspace
65-
# Note: This is a job which is defined above and not part of the Orb
66-
- checkout_code
67-
- install-dependencies:
129+
- install-dependencies
130+
- lint:
68131
requires:
69-
- checkout_code
70-
71-
# Analyze the Javascript using ESLint, Flow, and Jest
72-
# Note: This is a job which is defined above and not part of the Orb
73-
- analyse_js:
132+
- install-dependencies
133+
- typescript:
74134
requires:
75135
- install-dependencies
76-
77-
# Build the Android app in debug mode
78-
- rn/android_build:
79-
name: build_android
80-
project_path: "example/android"
81-
build_type: debug
136+
- e2e_release_ios:
137+
requires:
138+
- install-dependencies
139+
- e2e_release_android:
82140
requires:
83-
- analyse_js
141+
- install-dependencies

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
module.exports = {
22
root: true,
33
extends: '@react-native-community',
4+
globals: {
5+
expect: true,
6+
element: true,
7+
by: true,
8+
device: true,
9+
beforeAll: true,
10+
beforeEach: true,
11+
describe: true,
12+
it: true,
13+
afterAll: true,
14+
jest: true,
15+
jasmine: true,
16+
waitFor: true,
17+
detoxCircus: true,
18+
},
419
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ buck-out/
5757

5858
example/ios/Pods/
5959
!debug.keystore
60+
test-butler-app.apk

android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ PagerView_kotlinVersion=1.3.50
22
PagerView_compileSdkVersion=29
33
PagerView_buildToolsVersion=29.0.2
44
PagerView_targetSdkVersion=29
5-
PagerView_minSdkVersion=17
5+
PagerView_minSdkVersion=18

example/.detoxrc.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"testRunner": "jest",
3+
"runnerConfig": "e2e/config.json",
4+
"apps": {
5+
"ios.debug": {
6+
"type": "ios.app",
7+
"binaryPath": "./ios/build/Build/Products/Debug-iphonesimulator/PagerViewExample.app",
8+
"build": "xcodebuild -workspace ios/PagerViewExample.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 11' -scheme PagerViewExample -configuration Debug -derivedDataPath ios/build -UseModernBuildSystem=YES"
9+
},
10+
"ios.release": {
11+
"type": "ios.app",
12+
"binaryPath": "ios/build/Build/Products/Release-iphonesimulator/PagerViewExample.app",
13+
"build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/PagerViewExample.xcworkspace -configuration release -scheme PagerViewExample -sdk iphonesimulator -derivedDataPath ios/build"
14+
},
15+
"android.debug": {
16+
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
17+
"testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
18+
"build": "export RCT_NO_LAUNCH_PACKAGER=true && (cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug)",
19+
"type": "android.apk"
20+
},
21+
"android.release": {
22+
"binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
23+
"build": "export RCT_NO_LAUNCH_PACKAGER=true && (cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release)",
24+
"type": "android.apk"
25+
}
26+
},
27+
"devices": {
28+
"simulator": {
29+
"type": "ios.simulator",
30+
"device": {
31+
"type": "iPhone 11"
32+
}
33+
},
34+
"emulator": {
35+
"type": "android.emulator",
36+
"utilBinaryPaths": ["./test-butler-app.apk"],
37+
"device": {
38+
"avdName": "TestingAVD"
39+
}
40+
}
41+
},
42+
"configurations": {
43+
"ios.sim.debug": {
44+
"device": "simulator",
45+
"app": "ios.debug"
46+
},
47+
"ios.sim.release": {
48+
"device": "simulator",
49+
"app": "ios.release"
50+
},
51+
"android.emu.debug": {
52+
"device": "emulator",
53+
"app": "android.debug"
54+
},
55+
"android.emu.release": {
56+
"device": "emulator",
57+
"app": "android.release"
58+
}
59+
}
60+
}

example/android/app/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import com.android.build.OutputFile
7777

7878
project.ext.react = [
7979
enableHermes: false, // clean and rebuild if changing
80-
entryFile: "index.tsx",
80+
entryFile: "index.js",
8181
]
8282

8383
apply from: "../../node_modules/react-native/react.gradle"
@@ -133,6 +133,9 @@ android {
133133
targetSdkVersion rootProject.ext.targetSdkVersion
134134
versionCode 1
135135
versionName "1.0"
136+
testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type
137+
// testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
138+
testInstrumentationRunner 'com.example.reactnativepagerview.DetoxTestAppJUnitRunner'
136139
}
137140
splits {
138141
abi {
@@ -159,7 +162,8 @@ android {
159162
// see https://reactnative.dev/docs/signed-apk-android.
160163
signingConfig signingConfigs.debug
161164
minifyEnabled enableProguardInReleaseBuilds
162-
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
165+
// proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
166+
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
163167
}
164168
}
165169
// applicationVariants are e.g. debug, release
@@ -205,6 +209,9 @@ dependencies {
205209
}
206210

207211
implementation project(':reactnativepagerview')
212+
androidTestImplementation('com.wix:detox:+')
213+
androidTestImplementation 'com.linkedin.testbutler:test-butler-library:2.2.1'
214+
androidTestUtil 'com.linkedin.testbutler:test-butler-app:2.2.1'
208215
}
209216

210217
task downloadDependencies() {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.example.reactnativepagerview;
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+
// Replace 'MainActivity' with the value of android:name entry in
19+
// <activity> in AndroidManifest.xml
20+
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
21+
22+
@Test
23+
public void runDetoxTests() {
24+
DetoxConfig detoxConfig = new DetoxConfig();
25+
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90;
26+
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60;
27+
detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60);
28+
29+
Detox.runTests(mActivityRule, detoxConfig);
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.reactnativepagerview;
2+
3+
import android.os.Bundle;
4+
5+
import com.linkedin.android.testbutler.TestButler;
6+
7+
import androidx.test.runner.AndroidJUnitRunner;
8+
9+
public class DetoxTestAppJUnitRunner extends AndroidJUnitRunner {
10+
@Override
11+
public void onStart() {
12+
TestButler.setup(getTargetContext());
13+
super.onStart();
14+
}
15+
16+
@Override
17+
public void finish(int resultCode, Bundle results) {
18+
TestButler.teardown(getTargetContext());
19+
super.finish(resultCode, results);
20+
}
21+
}

0 commit comments

Comments
 (0)