Skip to content

Commit

Permalink
Add E2E tests for Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-sajko committed Jun 29, 2024
1 parent 8ac9e7a commit d23b75a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .github/actions/build-ios/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Build iOS App'
description: 'Build the iOS app'
runs:
using: 'composite'
steps:
- name: Build iOS App
run: |
xcodebuild -project ios/WeatherApp.xcodeproj \
-scheme WeatherApp \
-configuration Debug \
-sdk iphonesimulator \
-derivedDataPath build
10 changes: 10 additions & 0 deletions .github/actions/install-android/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'Install Android dependencies'
description: 'Install dependencies for the project'
runs:
using: 'composite'
steps:
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
24 changes: 24 additions & 0 deletions .github/actions/install-ios/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Install iOS dependencies'
description: 'Install dependencies for the project'
runs:
using: 'composite'
steps:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true

- name: Install Bundler
shell: bash
run: bundle install
working-directory: ios

- name: Install CocoaPods
shell: bash
run: sudo gem install cocoapods

- name: Install Pods
shell: bash
run: pod install
working-directory: ios
12 changes: 12 additions & 0 deletions .github/actions/install-maestro/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Install Maestro dependencies'
description: 'Install dependencies for the project'
runs:
using: 'composite'
steps:
- name: Install dependencies and Maestro
shell: bash
run: |
export MAESTRO_VERSION=1.36.0
curl -Ls "https://get.maestro.mobile.dev" | bash
brew tap facebook/fb
brew install facebook/fb/idb-companion
52 changes: 52 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: E2E Tests

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
run-e2e-tests:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install
- uses: ./.github/actions/install-ios
- uses: ./.github/actions/install-android
- uses: ./.github/actions/install-maestro
- uses: ./.github/actions/build-ios

- name: Start iOS Simulator
run: |
# Find a simulator by name (e.g., iPhone 15)
DEVICE_ID=$(xcrun simctl list devices available --json | jq -r '.devices[] | .[] | select(.name == "iPhone 15") | .udid' | head -n 1)
DEVICE_STATE=$(xcrun simctl list devices available --json | jq -r --arg DEVICE_ID "$DEVICE_ID" '.devices[] | .[] | select(.udid == $DEVICE_ID) | .state')
if [ -z "$DEVICE_ID" ]; then
echo "No available simulator found for the criteria."
exit 1
fi
echo "DEVICE_ID=$DEVICE_ID" >> $GITHUB_ENV
if [ "$DEVICE_STATE" != "Booted" ]; then
# Boot the simulator if it's not already booted
xcrun simctl boot "$DEVICE_ID"
# Wait a bit for the simulator to boot
sleep 30
DEVICE_STATE=$(xcrun simctl list devices available --json | jq -r --arg DEVICE_ID "$DEVICE_ID" '.devices[] | .[] | select(.udid == $DEVICE_ID) | .state')
if [ "$DEVICE_STATE" != "Booted" ]; then
echo "Failed to boot the simulator in 30s with DEVICE_ID=$DEVICE_ID."
exit 1
fi
else
echo "Simulator with DEVICE_ID=$DEVICE_ID is already booted."
fi
- name: Run Maestro UI tests
run: |
export PATH="$PATH:$HOME/.maestro/bin"
xcrun simctl install $DEVICE_ID build/Build/Products/Debug-iphonesimulator/WeatherApp.app
maestro --device $DEVICE_ID test ./maestro/flow.yml APP_ID=org.reactjs.native.example.WeatherApp
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml → .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: CI
name: Unit Tests

on:
push:
Expand All @@ -10,7 +10,7 @@ on:
branches: ['main']

jobs:
unit-tests:
run-unit-tests:
runs-on: ubuntu-latest

strategy:
Expand Down

0 comments on commit d23b75a

Please sign in to comment.