Skip to content

Commit 95b6648

Browse files
committed
ci: use detox for ui test, opt code
1 parent 9c673c2 commit 95b6648

File tree

28 files changed

+1762
-1042
lines changed

28 files changed

+1762
-1042
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Test
1+
name: CI
22
on:
33
pull_request:
44
types: [opened, synchronize, reopened]
@@ -74,7 +74,8 @@ jobs:
7474
assets/**
7575
package.json
7676
!example/ios/**
77-
77+
example/e2e/**
78+
7879
- uses: actions/cache@v3
7980
name: Cache node_modules
8081
if: steps.verify-android-changed-files.outputs.files_changed == 'true'
@@ -143,7 +144,7 @@ jobs:
143144
name: app-release-${{ github.sha }}.apk
144145
path: ${{ github.workspace }}/example/android/app-release-${{ github.sha }}.apk
145146

146-
android-test:
147+
android-api-level-test:
147148
runs-on: macos-latest
148149
needs: android-build
149150
name: Android Test
@@ -165,6 +166,7 @@ jobs:
165166
assets/**
166167
package.json
167168
!example/ios/**
169+
example/e2e/**
168170
169171
- uses: actions/cache@v3
170172
name: Cache node_modules
@@ -247,6 +249,7 @@ jobs:
247249
assets/**
248250
package.json
249251
!example/android/**
252+
example/e2e/**
250253
251254
- uses: actions/cache@v3
252255
name: Cache node_modules

README.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
[![stars](https://img.shields.io/github/stars/jimmydaddy/react-native-image-marker?style=social)](https://github.com/JimmyDaddy/react-native-image-marker) [![forks](https://img.shields.io/github/forks/jimmydaddy/react-native-image-marker?style=social)](https://github.com/JimmyDaddy/react-native-image-marker/fork)
1313
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?logo=github)](https://github.com/JimmyDaddy/react-native-image-marker/pulls) ![license](https://img.shields.io/npm/l/react-native-image-marker)
1414
[![github](https://img.shields.io/badge/github-repo-blue?logo=github)](https://github.com/JimmyDaddy/react-native-image-marker)
15-
[![Native Build and Test](https://github.com/JimmyDaddy/react-native-image-marker/actions/workflows/native-ci.yml/badge.svg)](https://github.com/JimmyDaddy/react-native-image-marker/actions/workflows/native-ci.yml)
16-
![platform-iOS](https://img.shields.io/badge/iOS-black?logo=Apple) ![platform-Android](https://img.shields.io/badge/Android-black?logo=Android)
15+
[![CI](https://github.com/JimmyDaddy/react-native-image-marker/actions/workflows/ci.yml/badge.svg)](https://github.com/JimmyDaddy/react-native-image-marker/actions/workflows/ci.yml)
16+
![platform-iOS](https://img.shields.io/badge/iOS-black?logo=Apple) ![platform-Android](https://img.shields.io/badge/Android-black?logo=Android)
1717
<br/>
1818

1919
</div>

example/.detoxrc.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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/ImageMarkerExample.app',
16+
build: 'xcodebuild -workspace ios/ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build'
17+
},
18+
'ios.release': {
19+
type: 'ios.app',
20+
binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/ImageMarkerExample.app',
21+
build: 'xcodebuild -workspace ios/ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -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+
reversePorts: [
28+
8081
29+
]
30+
},
31+
'android.release': {
32+
type: 'android.apk',
33+
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
34+
build: 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release'
35+
}
36+
},
37+
devices: {
38+
simulator: {
39+
type: 'ios.simulator',
40+
device: {
41+
type: 'iPhone 15'
42+
}
43+
},
44+
attached: {
45+
type: 'android.attached',
46+
device: {
47+
adbName: '.*'
48+
}
49+
},
50+
emulator: {
51+
type: 'android.emulator',
52+
device: {
53+
avdName: 'Pixel_XL_API_34'
54+
}
55+
}
56+
},
57+
configurations: {
58+
'ios.sim.debug': {
59+
device: 'simulator',
60+
app: 'ios.debug'
61+
},
62+
'ios.sim.release': {
63+
device: 'simulator',
64+
app: 'ios.release'
65+
},
66+
'android.att.debug': {
67+
device: 'attached',
68+
app: 'android.debug'
69+
},
70+
'android.att.release': {
71+
device: 'attached',
72+
app: 'android.release'
73+
},
74+
'android.emu.debug': {
75+
device: 'emulator',
76+
app: 'android.debug'
77+
},
78+
'android.emu.release': {
79+
device: 'emulator',
80+
app: 'android.release'
81+
}
82+
}
83+
};

example/android/app/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ android {
100100
targetSdkVersion rootProject.ext.targetSdkVersion
101101
versionCode 1
102102
versionName "1.0"
103+
testBuildType System.getProperty('testBuildType', 'debug')
104+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
103105
}
104106

105107
splits {
@@ -134,6 +136,7 @@ android {
134136
signingConfig signingConfigs.release
135137
minifyEnabled enableProguardInReleaseBuilds
136138
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
139+
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
137140
}
138141
}
139142

@@ -174,6 +177,10 @@ dependencies {
174177
testImplementation 'junit:junit:4.13.2'
175178
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
176179
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
180+
androidTestImplementation('com.wix:detox:+')
181+
implementation 'androidx.appcompat:appcompat:1.1.0'
182+
implementation project(':react-native-vector-icons')
177183
}
178184

179185
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
186+
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.imagemarkerexample;
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 // (2)
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+
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
android:icon="@mipmap/ic_launcher"
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:allowBackup="false"
11+
android:networkSecurityConfig="@xml/network_security_config"
12+
android:usesCleartextTraffic="true"
1113
android:theme="@style/AppTheme">
1214
<activity
1315
android:name=".MainActivity"

example/android/app/src/main/java/com/imagemarkerexample/MainApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.facebook.react.defaults.DefaultReactNativeHost;
1010
import com.facebook.soloader.SoLoader;
1111
import java.util.List;
12+
import com.oblador.vectoricons.VectorIconsPackage;
1213

1314
public class MainApplication extends Application implements ReactApplication {
1415

@@ -25,6 +26,7 @@ protected List<ReactPackage> getPackages() {
2526
List<ReactPackage> packages = new PackageList(this).getPackages();
2627
// Packages that cannot be autolinked yet can be added manually here, for example:
2728
// packages.add(new MyReactNativePackage());
29+
packages.add(new VectorIconsPackage());
2830
return packages;
2931
}
3032

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>

example/android/build.gradle

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

3+
34
buildscript {
4-
ext {
5+
def kotlin_version = project.properties["ImageMarkerExample_kotlinVersion"]
6+
ext {
57
buildToolsVersion = "33.0.0"
68
minSdkVersion = 24
79
compileSdkVersion = 33
810
targetSdkVersion = 33
911

1012
// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
1113
ndkVersion = "23.1.7779620"
14+
kotlinVersion = "$kotlin_version"
1215
}
1316
repositories {
1417
google()
@@ -18,9 +21,28 @@ buildscript {
1821
maven { url "https://repository.jboss.org/maven2" }
1922
maven { url 'https://maven.google.com' }
2023
maven { url 'https://maven.fabric.io/public' }
24+
maven {
25+
url("$rootDir/../node_modules/detox/Detox-android")
26+
}
2127
}
2228
dependencies {
2329
classpath('com.android.tools.build:gradle:7.4.2')
2430
classpath("com.facebook.react:react-native-gradle-plugin")
31+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
32+
}
33+
}
34+
35+
allprojects {
36+
repositories {
37+
google()
38+
mavenCentral()
39+
jcenter()
40+
maven { url 'https://dl.google.com/dl/android/maven2' }
41+
maven { url "https://repository.jboss.org/maven2" }
42+
maven { url 'https://maven.google.com' }
43+
maven { url 'https://maven.fabric.io/public' }
44+
maven {
45+
url("$rootDir/../node_modules/detox/Detox-android")
2546
}
47+
}
2648
}

example/android/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ newArchEnabled=false
4242
# Use this property to enable or disable the Hermes JS engine.
4343
# If set to false, you will be using JSC instead.
4444
hermesEnabled=true
45+
46+
ImageMarkerExample_kotlinVersion=1.7.0
47+

example/android/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ rootProject.name = 'ImageMarkerExample'
22
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
33
include ':app'
44
includeBuild('../node_modules/react-native-gradle-plugin')
5+
include ':react-native-vector-icons'
6+
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')

example/babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ module.exports = {
1414
},
1515
],
1616
],
17+
env: {
18+
production: {
19+
plugins: ['react-native-paper/babel'],
20+
},
21+
},
1722
};

example/e2e/App.test.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { device, element, by, waitFor } from 'detox';
2+
import assert from 'power-assert';
3+
4+
describe('e2e/App.test.js', () => {
5+
beforeAll(async () => {
6+
await device.launchApp();
7+
});
8+
9+
beforeEach(async () => {
10+
await device.reloadReactNative();
11+
});
12+
13+
it('should display correctly', async () => {
14+
await expect(element(by.id('backgroundImageFormatLabel'))).toBeVisible();
15+
await expect(element(by.id('backgroundImageFormatLabel'))).toHaveText(
16+
'background image format:'
17+
);
18+
19+
await expect(element(by.id('backgroundImageFormatBtn'))).toBeVisible();
20+
await expect(element(by.id('backgroundImageFormatBtn'))).toHaveLabel(
21+
'image'
22+
);
23+
24+
await expect(element(by.id('watermarkTypeLabel'))).toBeVisible();
25+
await expect(element(by.id('watermarkTypeLabel'))).toHaveText(
26+
'watermark type:'
27+
);
28+
29+
await expect(element(by.id('watermarkTypeBtn'))).toBeVisible();
30+
await expect(element(by.id('watermarkTypeBtn'))).toHaveLabel('text');
31+
32+
await expect(element(by.id('exportResultFormatLabel'))).toBeVisible();
33+
await expect(element(by.id('exportResultFormatLabel'))).toHaveText(
34+
'export result format:'
35+
);
36+
37+
await expect(element(by.id('exportResultFormatBtn'))).toBeVisible();
38+
await expect(element(by.id('exportResultFormatBtn'))).toHaveLabel('png');
39+
40+
await expect(element(by.id('selectBgBtn'))).toBeVisible();
41+
await expect(element(by.id('selectBgBtn'))).toHaveLabel('select bg');
42+
43+
// await expect(element(by.id('selectWatermarkBtn'))).toBeVisible();
44+
// await expect(element(by.id('selectWatermarkBtn'))).toHaveLabel(
45+
// 'select watermark'
46+
// );
47+
48+
await expect(element(by.id('resultFileSizeLabel'))).toBeVisible();
49+
await expect(element(by.id('resultFilePathLabel'))).toBeVisible();
50+
if (device.getPlatform() === 'ios') {
51+
const resultFileSizeLabel = await element(
52+
by.id('resultFileSizeLabel')
53+
).getAttributes('text');
54+
55+
assert.ok(
56+
/^result file size:\d+(.\d+)?\s(KB|MB)$/.test(resultFileSizeLabel.text)
57+
);
58+
const resultFilePathLabel = await element(
59+
by.id('resultFilePathLabel')
60+
).getAttributes('text');
61+
assert.ok(/^file path:.*\.png$/.test(resultFilePathLabel.text));
62+
} else {
63+
await expect(element(by.id('resultFileSizeLabel'))).toHaveLabel(
64+
/^result file size:\d+(\.\d+)?\s(KB|MB)$/
65+
);
66+
await expect(element(by.id('resultFilePathLabel'))).toBeVisible();
67+
await expect(element(by.id('resultFilePathLabel'))).toHaveText(
68+
/^file path:.*\.png$/
69+
);
70+
}
71+
72+
await expect(element(by.id('resultImage'))).toBeVisible();
73+
});
74+
75+
describe('when click backgroundImageFormatBtn', () => {
76+
it('should display correctly', async () => {
77+
await expect(element(by.id('backgroundImageFormatBtn'))).toHaveLabel(
78+
'image'
79+
);
80+
await element(by.id('backgroundImageFormatBtn')).tap();
81+
await waitFor(element(by.type('RCTModalHostView')))
82+
.toBeVisible()
83+
.withTimeout(2000);
84+
await element(by.label('base64')).tap();
85+
await expect(element(by.id('backgroundImageFormatBtn'))).toHaveLabel(
86+
'base64'
87+
);
88+
});
89+
});
90+
});

0 commit comments

Comments
 (0)