Skip to content

Commit cbc6c82

Browse files
author
yandadaFreedom
committed
feat: 添加detox配置
1 parent fdf793a commit cbc6c82

File tree

24 files changed

+577
-28130
lines changed

24 files changed

+577
-28130
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/** @type {Detox.DetoxConfig} */
2+
module.exports = {
3+
testRunner: {
4+
args: {
5+
$0: 'jest',
6+
config: 'e2e/jest.config.js'
7+
},
8+
jest: {
9+
setupTimeout: 120000
10+
}
11+
},
12+
apps: {
13+
'ios.debug': {
14+
type: 'ios.app',
15+
binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/ReactNativeProject.app',
16+
build: 'xcodebuild -workspace ios/ReactNativeProject.xcworkspace -scheme ReactNativeProject -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build'
17+
},
18+
'ios.release': {
19+
type: 'ios.app',
20+
binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/ReactNativeProject.app',
21+
build: 'xcodebuild -workspace ios/ReactNativeProject.xcworkspace -scheme ReactNativeProject -configuration Release -sdk iphonesimulator -derivedDataPath ios/build'
22+
},
23+
'android.debug': {
24+
type: 'android.apk',
25+
binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
26+
build: 'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug'
27+
},
28+
'android.release': {
29+
type: 'android.apk',
30+
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
31+
build: 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release'
32+
}
33+
},
34+
devices: {
35+
simulator: {
36+
type: 'ios.simulator',
37+
device: {
38+
type: 'iPhone 15'
39+
}
40+
},
41+
emulator: {
42+
type: 'android.emulator',
43+
device: {
44+
avdName: 'Pixel_8_API_35'
45+
}
46+
}
47+
},
48+
configurations: {
49+
'ios.sim.debug': {
50+
device: 'simulator',
51+
app: 'ios.debug'
52+
},
53+
'ios.sim.release': {
54+
device: 'simulator',
55+
app: 'ios.release'
56+
},
57+
'android.emu.debug': {
58+
device: 'emulator',
59+
app: 'android.debug'
60+
},
61+
'android.emu.release': {
62+
device: 'emulator',
63+
app: 'android.release'
64+
}
65+
}
66+
}
67+

test/e2e/miniprogram-cli-project/ReactNativeProject/android/app/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ android {
8484
targetSdkVersion rootProject.ext.targetSdkVersion
8585
versionCode 1
8686
versionName "1.0"
87+
88+
// Detox 配置
89+
testBuildType System.getProperty('testBuildType', 'debug')
90+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
8791
}
8892
signingConfigs {
8993
debug {
@@ -103,6 +107,8 @@ android {
103107
signingConfig signingConfigs.debug
104108
minifyEnabled enableProguardInReleaseBuilds
105109
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
110+
// Detox ProGuard 规则
111+
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
106112
}
107113
}
108114
}
@@ -116,4 +122,8 @@ dependencies {
116122
} else {
117123
implementation jscFlavor
118124
}
125+
126+
// Detox 依赖
127+
androidTestImplementation('com.wix:detox:+')
128+
implementation 'androidx.appcompat:appcompat:1.6.1'
119129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.reactnativeproject;
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+
}
30+

test/e2e/miniprogram-cli-project/ReactNativeProject/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:allowBackup="false"
1111
android:theme="@style/AppTheme"
12-
android:supportsRtl="true">
12+
android:supportsRtl="true"
13+
android:networkSecurityConfig="@xml/network_security_config">
1314
<activity
1415
android:name=".MainActivity"
1516
android:label="@string/app_name"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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>
8+

test/e2e/miniprogram-cli-project/ReactNativeProject/android/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,15 @@ buildscript {
1818
}
1919
}
2020

21+
allprojects {
22+
repositories {
23+
google()
24+
mavenCentral()
25+
maven {
26+
// Detox 本地仓库
27+
url("$rootDir/../node_modules/detox/Detox-android")
28+
}
29+
}
30+
}
31+
2132
apply plugin: "com.facebook.react.rootproject"

0 commit comments

Comments
 (0)