Skip to content

Instantly share code, notes, and snippets.

@Grohden
Created March 19, 2020 16:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Grohden/2ea8975d51754117ea15977338d89293 to your computer and use it in GitHub Desktop.
Save Grohden/2ea8975d51754117ea15977338d89293 to your computer and use it in GitHub Desktop.
Azure devops detox run tests for ios and android
trigger:
- none
pool:
vmImage: 'ubuntu-latest'
variables:
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
steps:
- task: NodeTool@0
inputs:
versionSpec: '12.9.1'
displayName: 'Install Node'
- task: Cache@2
inputs:
key: 'gradle | "$(Agent.OS)"'
restoreKeys: gradle
path: $(GRADLE_USER_HOME)
displayName: 'Gradle build cache'
- task: Cache@2
inputs:
key: 'yarn | "$(Agent.OS)" | yarn.lock'
restoreKeys: |
yarn | "$(Agent.OS)"
yarn
path: $(YARN_CACHE_FOLDER)
displayName: 'Cache Yarn packages'
- script: yarn --frozen-lockfile
displayName: 'Install dependencies'
- task: Cache@2
inputs:
key: 'AVD_IMAGES_29'
path: '$(ANDROID_HOME)/system-images'
cacheHitVar: 'AVD_IMAGES_RESTORED'
continueOnError: true
condition: succeededOrFailed()
displayName: 'Caching System Images for AVD'
- script: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-29;google_apis;x86"
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name emu --device "Nexus 5X" -k 'system-images;android-29;google_apis;x86'
$ANDROID_HOME/emulator/emulator -list-avds
condition: ne(variables.AVD_IMAGES_RESTORED, 'true')
displayName: 'Download Android Emulator Image'
- script: yarn detox:build
displayName: 'Build detox'
- script: |
echo "Starting emulator"
nohup $ANDROID_HOME/emulator/emulator -avd emu -no-snapshot -no-audio -no-boot-anim -accel auto -gpu auto -qemu -lcd-density 420 > /dev/null 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
$ANDROID_HOME/platform-tools/adb devices
echo "Emulator started"
displayName: 'Android Emulator'
- script: yarn detox:run
displayName: 'Detox test'
trigger:
- none
pool:
vmImage: 'macos-latest'
variables:
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
steps:
- task: NodeTool@0
inputs:
versionSpec: '12.9.1'
displayName: 'Install Node'
- task: Cache@2
inputs:
key: 'yarn | "$(Agent.OS)" | yarn.lock'
restoreKeys: |
yarn | "$(Agent.OS)"
yarn
path: $(YARN_CACHE_FOLDER)
displayName: 'Cache Yarn packages'
- script: yarn --frozen-lockfile
displayName: 'Install dependencies'
- script: |
yarn codegen
yarn type-check
displayName: 'Codegen and type-check'
- task: CocoaPods@0
inputs:
workingDirectory: 'ios'
forceRepoUpdate: false
- script: |
brew tap wix/brew
brew install applesimutils
displayName: 'Install Detox Tools'
- script: |
yarn detox:build
displayName: 'Build detox'
- script: |
yarn detox:test
displayName: 'Detox test'
@badsyntax
Copy link

The emulator would not complete the boot sequence for me on ubuntu, it just forever hanged, and I had to use a macos agent for android.

The docs also state:

Note: The Android Emulator is currently available only on the Hosted macOS agent.

@asenmitrev
Copy link

You are a god among men, worked on macOs-latest out of the box with minor tweaks.

@Grohden
Copy link
Author

Grohden commented Jul 30, 2021

@badsyntax you're right, it doesn't work on non macos agents.. I recall myself trying the android/ubuntu-latest one only to find out it doesn't support emulator... so I switched to macos one

Now I would consider trying the official docker image for RN in the android one (I don't recall how to use azure devops in depth anymore so I won't be updating this gists XD)

@asenmitrev
thank you, I'm really glad I can help other devs ❤️

@tomasfly
Copy link

Could you share which parameters are you passing to avdmanager and emulator tools? In my case, it gets stuck on adb wait-for-device

I am using macOs-latest image

@Grohden
Copy link
Author

Grohden commented Jun 29, 2022

@tomasfly I'm sorry, I'm not using azure since some months after posting this

You can however try to boot the emulator without the nohup part and look at the logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment