Skip to content

Commit

Permalink
feat: added react native detox framework for e2e automation (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanskar2001 authored Dec 26, 2024
1 parent 54f2284 commit 0145a42
Show file tree
Hide file tree
Showing 21 changed files with 499 additions and 14 deletions.
99 changes: 99 additions & 0 deletions .detoxrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/** @type {Detox.DetoxConfig} */
module.exports = {
testRunner: {
args: {
$0: 'jest',
config: 'detox-tests/e2e/jest.config.js',
},
jest: {
setupTimeout: 120000,
},
},
apps: {
'ios.debug': {
type: 'ios.app',
binaryPath:
'ios/build/Build/Products/Debug-iphonesimulator/HyperSwitch.app',
build:
'xcodebuild -workspace ios/hyperswitch.xcworkspace -scheme hyperswitch -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/demo-app/build/outputs/apk/debug/demo-app-debug.apk',
testBinaryPath:
'android/demo-app/build/outputs/apk/androidTest/debug/demo-app-debug-androidTest.apk',
build:
'cd android ; ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug ; cd -',
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: 'Pixel_3a_API_34_extension_level_7_arm64-v8a',
},
},
ciEmulator: {
type: 'android.emulator',
device: {
avdName: 'Pixel_API_29_AOSP',
},
},
},
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.ci.debug': {
device: 'ciEmulator',
app: 'android.debug',
},
'android.emu.release': {
device: 'emulator',
app: 'android.release',
},
},
};
1 change: 1 addition & 0 deletions .en
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ HYPERSWITCH_SECRET_KEY=""
HYPERSWITCH_SENTRY_DSN=""
HYPERSWITCH_CODEPUSH_ANDROID_KEY=""
HYPERSWITCH_CODEPUSH_IOS_KEY=""
PROFILE_ID=""
116 changes: 116 additions & 0 deletions .github/workflows/android-detox-automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# .github/workflows/e2e-android.yml
name: e2e-android
on: push

jobs:
e2e-android:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Free Disk Space
run: |
sudo rm -rf /opt/hostedtoolcache
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
- 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: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
# cache: 'npm'
# cache-dependency-path: '**/package-lock.json'

- name: Install dependencies
run: npm install

- name: Create .env file
run: |
touch .env
echo ${{ secrets.HYPERSWITCH_PUBLISHABLE_KEY }}
echo STATIC_DIR = ./dist >> .env
echo HYPERSWITCH_PUBLISHABLE_KEY = ${{ secrets.HYPERSWITCH_PUBLISHABLE_KEY }}>> .env
echo HYPERSWITCH_SECRET_KEY = ${{ secrets.HYPERSWITCH_SECRET_KEY }}>> .env
echo PROFILE_ID = ${{ secrets.PROFILE_ID }}>> .env
- name: Start server
run: |
nohup node server.js &
- name: Check Server
run: |
curl http://localhost:5252/create-payment-intent
- name: Setup Java
uses: actions/setup-java@v3
with:
cache: gradle
distribution: temurin
java-version: 17

# - name: Cache Detox build
# id: cache-detox-build
# uses: actions/cache@v3
# with:
# path: android/app/build
# key: ${{ runner.os }}-detox-build
# restore-keys: |
# ${{ runner.os }}-detox-build

# - name: List branches
# run: |
# cd android
# git fetch --all
# git branch -r

- name: Checkout Android Repo
uses: actions/checkout@v4
with:
repository: juspay/hyperswitch-sdk-android
ref: detox-poc
path: android
fetch-depth: 0

- name: Check Android branch
run: |
cd android && git branch && cd ..
- name: Generate & Supply JS Bundle to Test APK
run: |
npm run re:start && npm run bundle:android
- name: Detox build
run: cd android && ls && cd .. && npx detox build --configuration android.emu.ci.debug

- name: Get device name
id: device
run: node -e "console.log('AVD_NAME=' + require('./.detoxrc').devices.ciEmulator.device.avdName)" >> $GITHUB_OUTPUT

- name: Check Android branch
run: |
cd android && git branch && cd ..
- name: Detox test
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 30
target: default
arch: x86_64
profile: pixel
avd-name: ${{ steps.device.outputs.AVD_NAME }}
script: npx detox test --configuration android.emu.ci.debug --headless --loglevel trace --record-logs all

- name: Upload artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: detox-artifacts
path: artifacts
111 changes: 111 additions & 0 deletions .github/workflows/iOS-detox-automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# .github/workflows/e2e-ios.yml
name: e2e-ios
on: push

jobs:
e2e-ios:
runs-on: macos-14
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Checkout iOS Repo
uses: actions/checkout@v4
with:
repository: juspay/hyperswitch-sdk-ios
ref: main
path: ios
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Dependency Install
run: |
jq 'del(.resolutions) |
del(.dependencies["react-native-hyperswitch-netcetera-3ds"]) |
del(.dependencies["react-native-hyperswitch-scancard"])' package.json > package.json.tmp &&
mv package.json.tmp package.json
npm install
- name: Create .env file
run: |
touch .env
echo ${{ secrets.HYPERSWITCH_PUBLISHABLE_KEY }}
echo STATIC_DIR = ./dist >> .env
echo HYPERSWITCH_PUBLISHABLE_KEY = ${{ secrets.HYPERSWITCH_PUBLISHABLE_KEY }}>> .env
echo HYPERSWITCH_SECRET_KEY = ${{ secrets.HYPERSWITCH_SECRET_KEY }}>> .env
echo PROFILE_ID = ${{ secrets.PROFILE_ID }}>> .env
- name: Start server
run: |
nohup node server.js &
- name: Check Server
run: |
curl http://localhost:5252/create-payment-intent
- name: Install macOS dependencies
run: |
brew tap wix/brew
brew install applesimutils
env:
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1

# - name: Setup Ruby, JRuby and TruffleRuby
# uses: ruby/setup-ruby@v1.204.0

# - name: Cache CocoaPods
# id: cache-cocoapods
# uses: actions/cache@v3
# with:
# path: ios/Pods
# key: ${{ runner.os }}-pods-${{ hashFiles('ios/Podfile.lock') }}
# restore-keys: |
# ${{ runner.os }}-pods-

- name: Install CocoaPods
run: |
ls
cd ios
ls
pod setup --verbose
sudo gem install cocoapods
pod install
cd ..
- name: Detox rebuild framework cache
run: npx detox rebuild-framework-cache

- name: Start Rescript
run: |
npm run re:start
- name: Start Metro
run: |
nohup npm run start &
- name: Cache Detox build
id: cache-detox-build
uses: actions/cache@v3
with:
path: ios/build
key: ${{ runner.os }}-detox-build
restore-keys: |
${{ runner.os }}-detox-build
- name: Detox build
run: npx detox build --configuration ios.sim.debug

- name: Detox test
run: npx detox test --configuration ios.sim.debug --loglevel trace --record-logs all

- name: Upload artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: detox-artifacts
path: artifacts
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ hyperswitch-react-native/lib/bs/
#next
.next/
next-env.d.ts
/out
/out

#detox
*.log
*.trace.json
*.detox.jsonl
8 changes: 8 additions & 0 deletions detox-tests/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
presets: [
'@babel/preset-env', // Handles modern JavaScript features like `export`
],
plugins: [
'@babel/plugin-transform-modules-commonjs', // Transforms ES modules to CommonJS for Jest compatibility
],
};
Loading

0 comments on commit 0145a42

Please sign in to comment.