Skip to content

Commit

Permalink
Detox e2e tests
Browse files Browse the repository at this point in the history
Setup Detox
Added documentation for detox
Added testIds
Added setup tests for Launch Screen, Home Screen, Conversation Screen Added helper utils for tests

Draft PR while finalizing Android Setup
  • Loading branch information
Alex Risch authored and Alex Risch committed Dec 21, 2023
1 parent e95063a commit 38bec7e
Show file tree
Hide file tree
Showing 27 changed files with 1,669 additions and 16,550 deletions.
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 @@ -53,6 +53,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 @@ -35,4 +35,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
```
49 changes: 24 additions & 25 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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 @@ -130,23 +131,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 @@ -176,6 +177,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 @@ -261,13 +263,10 @@ dependencies {
}

// For Espresso
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10"
implementation "androidx.tracing:tracing:1.1.0"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5"
androidTestUtil "androidx.test.services:test-services:1.4.2"
androidTestUtil 'androidx.test:orchestrator:1.4.2'
// For Detox
androidTestImplementation 'com.google.protobuf:protobuf-kotlin-lite:3.22.3'
androidTestImplementation 'org.xmtp:proto-kotlin:3.31.0'
androidTestImplementation 'com.wix:detox:+'
}

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.

2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@anonymous/xmtp-react-native-sdk-example"/>
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait" android:networkSecurityConfig="@xml/network_security_config">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>

Loading

0 comments on commit 38bec7e

Please sign in to comment.