Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detox e2e tests #182

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .github/workflows/androidTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ jobs:
- name: Start local test server
run: docker-compose -p xmtp -f dev/local/docker-compose.yml up -d

- name: Gradle Run Integration Tests
uses: reactivecircus/android-emulator-runner@v2
with:
working-directory: ./example
api-level: 29
script: |
react-native run-android
sleep 15
cd android && ./gradlew connectedCheck
- name: Build Android app
run: |
cd example
react-native run-android

- name: Install Detox command line tools
run: npm install -g detox-cli

- name: Build and test Android app
run: |
cd example
detox build -c android.emu.debug
detox test -c android.emu.debug

- name: Stop local test server
run: docker-compose -p xmtp -f dev/local/docker-compose.yml down
83 changes: 83 additions & 0 deletions example/.detoxrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/** @type {Detox.DetoxConfig} */
module.exports = {
testRunner: {
args: {
'$0': 'jest',
config: 'e2e/jest.config.js'
},
jest: {
setupTimeout: 120000
}
},
apps: {
'ios.debug': {
type: 'ios.app',
binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/xmtpreactnativesdkexample.app',
build: 'xcodebuild -workspace ios/xmtpreactnativesdkexample.xcworkspace -scheme xmtpreactnativesdkexample -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build',
},
'ios.release': {
type: 'ios.app',
binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/YOUR_APP.app',
build: 'xcodebuild -workspace ios/YOUR_APP.xcworkspace -scheme YOUR_APP -configuration Release -sdk iphonesimulator -derivedDataPath ios/build'
},
'android.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
build: 'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
reversePorts: [
8081
]
},
'android.release': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
build: 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release'
}
},
devices: {
simulator: {
type: 'ios.simulator',
device: {
type: 'iPhone 15'
}
},
attached: {
type: 'android.attached',
device: {
adbName: '.*'
}
},
emulator: {
type: 'android.emulator',
device: {
avdName: 'Pixel7'
}
}
},
configurations: {
'ios.sim.debug': {
device: 'simulator',
app: 'ios.debug'
},
'ios.sim.release': {
device: 'simulator',
app: 'ios.release'
},
'android.att.debug': {
device: 'attached',
app: 'android.debug'
},
'android.att.release': {
device: 'attached',
app: 'android.release'
},
'android.emu.debug': {
device: 'emulator',
app: 'android.debug'
},
'android.emu.release': {
device: 'emulator',
app: 'android.release'
}
}
};
1 change: 1 addition & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function App() {
onPress={() => navigation.navigate('conversationCreate')}
title="New"
color={Platform.OS === 'ios' ? '#fff' : 'rgb(49 0 110)'}
testID="new-conversation-button"
/>
),
})}
Expand Down
26 changes: 25 additions & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,28 @@ Running tests locally is useful when updating GitHub actions, or locally testing
5. You can stop the XMTP server with the following command:
```bash
docker-compose -p xmtp -f dev/local/docker-compose.yml down
```
```

## Run e2e tests for example app
Running e2e tests when updating example app with Detox

1. Setup [Detox Prerequisites](https://wix.github.io/Detox/docs/introduction/environment-setup#detox-prerequisites)

2. Update example/.detoxrc.js to match device configs - [More information on device config and debugging issues](https://wix.github.io/Detox/docs/introduction/project-setup#step-3-device-configs)

3. Build the app for testing:
```bash
detox build --configuration ios.sim.debug
```
or
```bash
detox build --configuration android.emu.debug
```
4. Run the tests:
```bash
detox test --configuration ios.sim.debug
```
or
```bash
detox test --configuration android.emu.debug
```
42 changes: 24 additions & 18 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0.0"
// For Espresso
// For Detox
testBuildType System.getProperty('testBuildType', 'debug')
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
testInstrumentationRunnerArgument('useTestStorageService', 'true')
// The following argument makes the Android Test Orchestrator run its
Expand All @@ -132,23 +133,23 @@ android {
testInstrumentationRunnerArgument('clearPackageData', 'true')
}

testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
managedDevices {
devices {
// run with ../gradlew nexusOneApi30DebugAndroidTest
nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) {
// A lower resolution device is used here for better emulator performance
device = "Nexus One"
apiLevel = 30
// Also use the AOSP ATD image for better emulator performance
// The androidx.test screenshot APIs will automatically enable hardware rendering
// to take a screenshot
systemImageSource = "aosp-atd"
}
}
}
}
// testOptions {
// execution 'ANDROIDX_TEST_ORCHESTRATOR'
// managedDevices {
// devices {
// // run with ../gradlew nexusOneApi30DebugAndroidTest
// nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) {
// // A lower resolution device is used here for better emulator performance
// device = "Nexus One"
// apiLevel = 30
// // Also use the AOSP ATD image for better emulator performance
// // The androidx.test screenshot APIs will automatically enable hardware rendering
// // to take a screenshot
// systemImageSource = "aosp-atd"
// }
// }
// }
// }

splits {
abi {
Expand Down Expand Up @@ -178,6 +179,7 @@ android {
signingConfig signingConfigs.debug
shrinkResources (findProperty('android.enableShrinkResourcesInReleaseBuilds')?.toBoolean() ?: false)
minifyEnabled enableProguardInReleaseBuilds
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
Expand Down Expand Up @@ -273,6 +275,10 @@ dependencies {

// For loading .env
implementation project(':react-native-config')
// For Detox
androidTestImplementation('com.wix:detox:+'){
exclude module: "protobuf-lite"
}
}

apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package expo.modules.xmtpreactnativesdk.example;

import com.wix.detox.Detox;
import com.wix.detox.config.DetoxConfig;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class DetoxTest {
@Rule // (2)
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);

@Test
public void runDetoxTests() {
DetoxConfig detoxConfig = new DetoxConfig();
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90;
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60;
detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60);

Detox.runTests(mActivityRule, detoxConfig);
}
}

This file was deleted.

This file was deleted.

Loading
Loading