Skip to content

Commit ee48f90

Browse files
Added Detox tests (#59)
* feat(PSG-5355): setup ios test app * feat(PSG-5357): setup detox tooling * test(PSG-5457): added Passage App tests * test(PSG-5457): simplify app tests * refactor: improved usability and readability of test setup * test(PSG-5347): added mailosaur infrastructure * test(PSG-5347): added otp tests * test(PSG-5348): added magic link tests * test(PSG-5352): added hosted test * test(PSG-5353): Added Social test * test(PSG-5351): Added current user tests * test(PSG-5350): added token store tests * refactor: improve test code performance and reusability * build(PSG-5513): added detox test workflow * test: disable eslint for test files * chore: cleanup app view * test: attempt to fix podfile issue with test app * test: attempt to fix build issue with test app * test: remove test app from library type check * test: attempt to fix pod install for test app * test: attempt to fix podfile issue with test app * test: attempt to fix podfile issue with test app * test: attempt to fix podfile issue with test app * test: attempt to fix podfile issue with test app * test: attempt to fix podfile issue with test app * test: attempt to fix podfile issue with test app * test: attempt to fix podfile issue with test app * test: attempt to fix podfile issue with test app * test: attempt to fix podfile issue with test app * fix: remove react-native-quick-base64 from test app * fix: add applesimutils to detox test workflow * test: use release build in detox tests * test: add wait to web view tests * test: extend web view test timeouts * test: extend test timeouts to reduce flakiness * test: adjust mailosaur timeout for tests * fix: adjusted timeout for waiting for successful test results * Update hosted.test.js * Android e2e detox test config (#60) * ops: added android detox test config
1 parent e303b0b commit ee48f90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+11891
-174
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ jobs:
2323
- name: Typecheck files
2424
run: yarn typecheck
2525

26-
test:
27-
runs-on: ubuntu-latest
28-
steps:
29-
- name: Checkout
30-
uses: actions/checkout@v3
31-
32-
- name: Setup
33-
uses: ./.github/actions/setup
34-
35-
- name: Run unit tests
36-
run: yarn test --maxWorkers=2 --coverage
37-
3826
build:
3927
runs-on: ubuntu-latest
4028
steps:

.github/workflows/detox-tests.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Detox Tests
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
ios-tests:
9+
runs-on: macos-latest
10+
11+
env:
12+
NODE_OPTIONS: "--max-old-space-size=4096"
13+
MAILOSAUR_API_KEY: ${{ secrets.MAILOSAUR_API_KEY }}
14+
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 16
23+
24+
- name: Install applesimutils
25+
run: |
26+
brew tap wix/brew
27+
brew install applesimutils
28+
29+
- name: Clean Derived Data
30+
run: |
31+
rm -rf ~/Library/Developer/Xcode/DerivedData
32+
33+
- name: Install Dependencies
34+
run: |
35+
rm -rf node_modules && npm install
36+
cd example && rm -rf node_modules && npm install
37+
cd ios && rm -rf Pods && pod cache clean --all && pod install && cd ..
38+
39+
- name: Run Detox iOS Tests
40+
working-directory: example
41+
run: |
42+
npx detox build --configuration ios.sim.release
43+
npx detox test --configuration ios.sim.release --cleanup
44+
shell: bash
45+
46+
android-tests:
47+
runs-on: ubuntu-latest
48+
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v4
52+
53+
- name: Set up Java
54+
uses: actions/setup-java@v3
55+
with:
56+
distribution: 'zulu'
57+
java-version: '17'
58+
59+
- name: Set up Node.js
60+
uses: actions/setup-node@v3
61+
with:
62+
node-version: 16
63+
64+
- name: Enable KVM
65+
run: |
66+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
67+
sudo udevadm control --reload-rules
68+
sudo udevadm trigger --name-match=kvm
69+
70+
- name: Set environment variables
71+
run: |
72+
echo "MAILOSAUR_API_KEY=${{ secrets.MAILOSAUR_API_KEY }}" > example/.env
73+
74+
- name: Install Dependencies
75+
run: |
76+
rm -rf node_modules && npm install
77+
cd example && rm -rf node_modules && npm install && cd ..
78+
79+
- name: Start emulator and run tests
80+
uses: reactivecircus/android-emulator-runner@v2
81+
with:
82+
api-level: 34
83+
target: google_apis
84+
arch: x86_64
85+
profile: Nexus 6
86+
working-directory: ./example
87+
script: |
88+
npx detox build --configuration android.emu.release
89+
npx detox test --configuration android.emu.release --cleanup

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ android/keystores/debug.keystore
6868

6969
# generated by bob
7070
lib/
71+
72+
*.env

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/PassageReactNativeExample.app',
16+
build: 'xcodebuild -workspace ios/PassageReactNativeExample.xcworkspace -scheme PassageReactNativeExample -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build'
17+
},
18+
'ios.release': {
19+
type: 'ios.app',
20+
binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/PassageReactNativeExample.app',
21+
build: 'xcodebuild -workspace ios/PassageReactNativeExample.xcworkspace -scheme PassageReactNativeExample -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: 'test'// Use something like 'Pixel_6_Pro_API_33' when testing locally
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: 5 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 {
@@ -128,6 +130,7 @@ android {
128130
signingConfig signingConfigs.debug
129131
minifyEnabled enableProguardInReleaseBuilds
130132
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
133+
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
131134
}
132135
}
133136

@@ -149,6 +152,8 @@ android {
149152
}
150153

151154
dependencies {
155+
androidTestImplementation('com.wix:detox-legacy:+')
156+
implementation 'androidx.appcompat:appcompat:1.1.0'
152157
// The version of react-native is set by the React Native Gradle Plugin
153158
implementation("com.facebook.react:react-android")
154159

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.example_reactnative;
2+
3+
import id.passage.example_reactnative.MainActivity;
4+
5+
import com.wix.detox.BuildConfig;
6+
import com.wix.detox.Detox;
7+
import com.wix.detox.config.DetoxConfig;
8+
9+
import org.junit.Rule;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
13+
import androidx.test.ext.junit.runners.AndroidJUnit4;
14+
import androidx.test.filters.LargeTest;
15+
import androidx.test.rule.ActivityTestRule;
16+
17+
@RunWith(AndroidJUnit4.class)
18+
@LargeTest
19+
public class DetoxTest {
20+
@Rule
21+
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
22+
23+
@Test
24+
public void runDetoxTests() {
25+
DetoxConfig detoxConfig = new DetoxConfig();
26+
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90;
27+
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60;
28+
detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60);
29+
30+
Detox.runTests(mActivityRule, detoxConfig);
31+
}
32+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:allowBackup="false"
1111
tools:targetApi="31"
12+
android:networkSecurityConfig="@xml/network_security_config"
1213
android:theme="@style/AppTheme">
1314
<meta-data
1415
android:name="asset_statements"
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<resources>
22
<string name="app_name">PassageReactNativeExample</string>
3-
<!-- Required Passage app settings -->
4-
<string name="passage_auth_origin">YOUR_AUTH_ORIGIN</string>
3+
<string name="passage_auth_origin">smoggy-orchid-mule.withpassage-uat.com</string>
54
<string name="asset_statements">
65
[{
76
\"include\": \"https://@string/passage_auth_origin/.well-known/assetlinks.json\"
87
}]
98
</string>
10-
9+
<string name="clientApiBasePath">https://auth-uat.passage.dev/v1</string>
1110
</resources>
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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
2+
allprojects {
3+
repositories {
4+
// ...
5+
google()
6+
maven {
7+
// All of Detox' artifacts are provided via the npm module
8+
url "$rootDir/../node_modules/detox/Detox-android"
9+
}
10+
}
11+
}
312
buildscript {
413
ext {
514
buildToolsVersion = "33.0.0"
@@ -13,6 +22,9 @@ buildscript {
1322
repositories {
1423
google()
1524
mavenCentral()
25+
maven { // (4)
26+
url("$rootDir/../node_modules/detox/Detox-android")
27+
}
1628
}
1729
dependencies {
1830
classpath("com.android.tools.build:gradle:7.3.1")

0 commit comments

Comments
 (0)