Skip to content

Commit

Permalink
Added Detox tests (#59)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rickycpadilla authored Dec 19, 2024
1 parent e303b0b commit ee48f90
Show file tree
Hide file tree
Showing 43 changed files with 11,891 additions and 174 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ jobs:
- name: Typecheck files
run: yarn typecheck

test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage

build:
runs-on: ubuntu-latest
steps:
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/detox-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Detox Tests

on:
pull_request:
branches: [main]

jobs:
ios-tests:
runs-on: macos-latest

env:
NODE_OPTIONS: "--max-old-space-size=4096"
MAILOSAUR_API_KEY: ${{ secrets.MAILOSAUR_API_KEY }}

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install applesimutils
run: |
brew tap wix/brew
brew install applesimutils
- name: Clean Derived Data
run: |
rm -rf ~/Library/Developer/Xcode/DerivedData
- name: Install Dependencies
run: |
rm -rf node_modules && npm install
cd example && rm -rf node_modules && npm install
cd ios && rm -rf Pods && pod cache clean --all && pod install && cd ..
- name: Run Detox iOS Tests
working-directory: example
run: |
npx detox build --configuration ios.sim.release
npx detox test --configuration ios.sim.release --cleanup
shell: bash

android-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Set environment variables
run: |
echo "MAILOSAUR_API_KEY=${{ secrets.MAILOSAUR_API_KEY }}" > example/.env
- name: Install Dependencies
run: |
rm -rf node_modules && npm install
cd example && rm -rf node_modules && npm install && cd ..
- name: Start emulator and run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
target: google_apis
arch: x86_64
profile: Nexus 6
working-directory: ./example
script: |
npx detox build --configuration android.emu.release
npx detox test --configuration android.emu.release --cleanup
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ android/keystores/debug.keystore

# generated by bob
lib/

*.env
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/PassageReactNativeExample.app',
build: 'xcodebuild -workspace ios/PassageReactNativeExample.xcworkspace -scheme PassageReactNativeExample -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build'
},
'ios.release': {
type: 'ios.app',
binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/PassageReactNativeExample.app',
build: 'xcodebuild -workspace ios/PassageReactNativeExample.xcworkspace -scheme PassageReactNativeExample -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: 'test'// Use something like 'Pixel_6_Pro_API_33' when testing locally
}
}
},
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'
}
}
};
5 changes: 5 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testBuildType System.getProperty('testBuildType', 'debug')
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

splits {
Expand Down Expand Up @@ -128,6 +130,7 @@ android {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
}
}

Expand All @@ -149,6 +152,8 @@ android {
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example_reactnative;

import id.passage.example_reactnative.MainActivity;

import com.wix.detox.BuildConfig;
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
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);
}
}
1 change: 1 addition & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
tools:targetApi="31"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">
<meta-data
android:name="asset_statements"
Expand Down
5 changes: 2 additions & 3 deletions example/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<resources>
<string name="app_name">PassageReactNativeExample</string>
<!-- Required Passage app settings -->
<string name="passage_auth_origin">YOUR_AUTH_ORIGIN</string>
<string name="passage_auth_origin">smoggy-orchid-mule.withpassage-uat.com</string>
<string name="asset_statements">
[{
\"include\": \"https://@string/passage_auth_origin/.well-known/assetlinks.json\"
}]
</string>

<string name="clientApiBasePath">https://auth-uat.passage.dev/v1</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?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>
14 changes: 13 additions & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

allprojects {
repositories {
// ...
google()
maven {
// All of Detox' artifacts are provided via the npm module
url "$rootDir/../node_modules/detox/Detox-android"
}
}
}
buildscript {
ext {
buildToolsVersion = "33.0.0"
Expand All @@ -13,6 +22,9 @@ buildscript {
repositories {
google()
mavenCentral()
maven { // (4)
url("$rootDir/../node_modules/detox/Detox-android")
}
}
dependencies {
classpath("com.android.tools.build:gradle:7.3.1")
Expand Down
16 changes: 16 additions & 0 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
pluginManagement {
buildscript {
repositories {
mavenCentral()
maven {
// r8 maven
url = uri("https://storage.googleapis.com/r8-releases/raw")
}
}
dependencies {
// r8 version
classpath("com.android.tools:r8:8.2.16-dev")
}
}
}

rootProject.name = 'PassageReactNativeExample'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
Expand Down
17 changes: 16 additions & 1 deletion example/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const path = require('path');
const pak = require('../package.json');

module.exports = {
presets: ['module:metro-react-native-babel-preset'],
presets: [
'module:metro-react-native-babel-preset',
'@babel/preset-typescript',
],
plugins: [
[
'module-resolver',
Expand All @@ -13,5 +16,17 @@ module.exports = {
},
},
],
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: '.env',
blocklist: null,
allowlist: null,
safe: false,
allowUndefined: false,
verbose: false,
},
],
],
};
Loading

0 comments on commit ee48f90

Please sign in to comment.