Description
I'm using Bitrise to run Detox tests. The build command runs ok and is a success. But the test command always fails.
Running locally:
Command detox test -c ios.sim.debug without starting the packager: 'No bundle URL present' error
Command detox test -c ios.sim.debug with the packager: Opens the packager and everything runs OK.
Command detox test -c ios.sim.release without the packager: works fine.
Command detox test -c ios.sim.release with the packager: works fine.
Running in Bitrise:
Command detox test -c ios.sim.debug --cleanup without starting the packager: 'No bundle URL present' error
Command detox test -c ios.sim.debug --cleanup with the packager:
Verify tests are up
"before all" hook:
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/vagrant/git/e2e/tests.spec.js)
Command detox test -c ios.sim.release --cleanup without the packager: works fine.
Command detox test -c ios.sim.release --cleanup with the packager: works fine.
Disclaimer
With/Without the packager means the variable RCT_NO_LAUNCH_PACKAGER equals false/true, respectively.
The package.json file
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/PROJECT_NAME.app",
"build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/PROJECT_NAME.xcworkspace -scheme INTEGRATION_SCHEME -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"name": "iPhone 7"
},
"ios.sim.release": {
"binaryPath": "ios/build/Build/Products/Release-iphonesimulator/PROJECT_NAME.app",
"build": "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -workspace ios/PROJECT_NAME.xcworkspace -scheme PRODUCTION_SCHEME -configuration Release -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"name": "iPhone 7 Plus"
},
The bitrise.yml file
_init_install:
steps:
- activate-ssh-key#3.1.1:
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
- git-clone#4.0.11: {}
- script#1.1.5:
inputs:
- content: |-
#!/usr/bin/env bash
# fail if any commands fails
set -e
# debug log
set -x
# write your script here
brew uninstall --ignore-dependencies node
brew install node#8
brew link --overwrite --force node#8
- yarn#0.0.7: {}
_detox_tests:
steps:
- npm#0.9.0:
title: Install Detox CLI
inputs:
- command: install -g detox-cli
- npm#0.9.0:
title: Install React-Native CLI
inputs:
- command: install -g react-native-cli
- script#1.1.5:
title: Install Detox Utils
inputs:
- content: |-
#!/bin/bash
brew tap facebook/fb
export CODE_SIGNING_REQUIRED=NO
brew install fbsimctl
brew tap wix/brew
brew install applesimutils --HEAD
- script#1.1.5:
title: Detox - Build Debug App
inputs:
- content: |-
#!/usr/bin/env bash
detox build -c ios.sim.debug
- script#1.1.5:
title: Detox - Run E2E Tests
inputs:
- content: |-
#!/usr/bin/env bash
detox test -c ios.sim.debug --cleanup
- deploy-to-bitrise-io#1.3.10: {}
test_ios:
before_run:
- _init_install
after_run:
- _detox_tests
steps:
- cocoapods-install#1.7.2:
inputs:
- podfile_path: ios/Podfile
- resource-archive#2.0.1:
inputs:
- extract_to_path: "$HOME/Documents/FacebookSDK/"
- archive_url:https://origincache.facebook.com/developers/resources/?id=facebook-ios-sdk-current.zip
- certificate-and-profile-installer#1.9.3: {}
```
Detox, Node, Device, Xcode and macOS Versions
Detox: v7.4.3
React Native: v0.51.0
Node: v9.4.0
Device: iPhone 7 (simulator)
Xcode: Version 9.3 (9E145)
macOS: 10.13.3 (17D102)
Device and verbose Detox logs
Error detox test -c ios.sim.debug --cleanup with the packager
pastebin
File detox.last_launch_app_log.err prints:
pastebin
TL;DR
I get an error when running Detox with Bitrise. The command detox test -c ios.sim.debug --cleanup should open a packager but looks like it's not doing it.
The version that is needed to test is the Debug one, no other options. Maybe I missed something about the installation, but all the files were checked with official docs and other examples and are the identical.
Related issues: 742, 749, 740
Related
when i am running this command it gives this error
Command:
- name: Build ipa for distribution
script: |
xcode-project build-ipa \
--workspace "$CM_BUILD_DIR/ios/$XCODE_WORKSPACE" \
--scheme "$XCODE_SCHEME"
Error Snapshot
xcode-project: error: argument --export-options-plist: Path "/Users/builder/export_options.plist" does not exist
Build failed :|
Step 6 script `Build ipa for distribution` exited with status code 2
Need to add xcode-project use-profiles step before building the IPA. Error seems to be missing code signing step.
- name: Install CocoaPods dependencies
script: |
cd ios && pod install
- name: Set up provisioning profiles settings on Xcode project
script: xcode-project use-profiles
- name: Build ipa for distribution
script: |
xcode-project build-ipa \
--workspace "$CM_BUILD_DIR/ios/$XCODE_WORKSPACE" \
--scheme "$XCODE_SCHEME"
Reference:
https://docs.codemagic.io/yaml-code-signing/signing-ios/
I have a .detoxrc.json with the following config:
"apps": {
"ios": {
"type": "ios.app",
"binaryPath": "./ios/build/Build/Products/Debug-iphonesimulator/<my-app-demo>.app",
"build": "xcodebuild -workspace ios/<my-app>.xcworkspace -configuration Debug -scheme '<my-app-demo>' -sdk iphonesimulator -derivedDataPath ios/build"
}
},
This works fine locally, and I'm able to build and test successfully.
However, in github actions it fails every time. I've tried running the step as yarn detox build -c ios and as the actual command from the "build" instruction, but no luck.
Here's what I'm currently trying to do in the action's yml file:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
jobs:
build:
name: iOS Simulator Tests
runs-on: macos-12
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Node
uses: actions/setup-node#v3
with:
node-version: 16
cache: "yarn"
- name: Cache node_modules
id: cache
uses: actions/cache#v2
with:
path: ./node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- name: Install node_modules
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: Pod Install
run: cd ios && pod install && cd ..
- name: Install Applesimutils
run: |
brew tap wix/brew
brew install applesimutils
- name: Detox build
run: yarn detox build -c ios
- name: Detox test
run: yarn detox test -c ios --cleanup
Why would this not work on a github runner? As far as I know there's no special config I should need for this to run.
EDIT: Here are the logs that are outputting on failure:
2022-10-17T13:20:19.5286140Z error: /Users/runner/work/buyer-app/buyer-app/ios/my-app/main.jsbundle: No such file or directory (in target 'my-app Feat' from project 'my-app')
2022-10-17T13:20:19.5286460Z
2022-10-17T13:20:19.5290650Z CpResource /Users/runner/work/buyer-app/buyer-app/ios/my-app/assets /Users/runner/work/buyer-app/buyer-app/ios/build/Build/Products/Debug-iphonesimulator/my-app\ Feat.app/assets (in target 'my-app Feat' from project 'my-app')
2022-10-17T13:20:19.5292650Z cd /Users/runner/work/buyer-app/buyer-app/ios
2022-10-17T13:20:19.5293830Z builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks /Users/runner/work/buyer-app/buyer-app/ios/my-app/assets /Users/runner/work/buyer-app/buyer-app/ios/build/Build/Products/Debug-iphonesimulator/my-app\ Feat.app
2022-10-17T13:20:19.5294950Z error: /Users/runner/work/buyer-app/buyer-app/ios/my-app/assets: No such file or directory (in target 'my-app Feat' from project 'my-app')
2022-10-17T13:20:19.5295230Z
2022-10-17T13:20:19.5296230Z CpResource /Users/runner/work/buyer-app/buyer-app/ios/my-app-Omega.ttf /Users/runner/work/buyer-app/buyer-app/ios/build/Build/Products/Debug-iphonesimulator/my-app\ Feat.app/my-app-Omega.ttf (in target 'my-app Feat' from project 'my-app')
2022-10-17T13:20:19.5296910Z cd /Users/runner/work/buyer-app/buyer-app/ios
2022-10-17T13:20:19.5297970Z builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks /Users/runner/work/buyer-app/buyer-app/ios/my-app-Omega.ttf /Users/runner/work/buyer-app/buyer-app/ios/build/Build/Products/Debug-iphonesimulator/my-app\ Feat.app
2022-10-17T13:20:19.5298790Z
2022-10-17T13:20:19.6324520Z ** BUILD FAILED **
2022-10-17T13:20:19.6324780Z
2022-10-17T13:20:19.6324790Z
2022-10-17T13:20:19.6325000Z The following build commands failed:
2022-10-17T13:20:19.6326500Z CpResource /Users/runner/work/buyer-app/buyer-app/ios/my-app/main.jsbundle /Users/runner/work/buyer-app/buyer-app/ios/build/Build/Products/Debug-iphonesimulator/my-app\ Feat.app/main.jsbundle (in target 'my-app Feat' from project 'my-app')
2022-10-17T13:20:19.6327810Z CpResource /Users/runner/work/buyer-app/buyer-app/ios/my-app/assets /Users/runner/work/buyer-app/buyer-app/ios/build/Build/Products/Debug-iphonesimulator/my-app\ Feat.app/assets (in target 'my-app Feat' from project 'my-app')
2022-10-17T13:20:19.6328290Z (2 failures)
2022-10-17T13:20:19.6446800Z 13:20:19.644 detox[12824] WARN: [build.js]
2022-10-17T13:20:19.6448980Z
2022-10-17T13:20:19.6450160Z Important: 'detox build' is a convenience shortcut for calling your own build command, as provided in the config file.
2022-10-17T13:20:19.6451260Z Failures in this build command are not the responsibility of Detox. You are responsible for maintaining this command.
2022-10-17T13:20:19.6451830Z
2022-10-17T13:20:19.6453150Z 13:20:19.644 detox[12824] ERROR: [cli.js] Command failed: xcodebuild -workspace ios/my-app.xcworkspace -configuration Debug -scheme 'my-app Feat' -sdk iphonesimulator -derivedDataPath ios/build
2022-10-17T13:20:19.6455530Z
2022-10-17T13:20:19.6647490Z error Command failed with exit code 1.
2022-10-17T13:20:19.6648170Z info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2022-10-17T13:20:19.6746380Z ##[error]Process completed with exit code 1.
I would like to run tests on two different builds of iOS, therefore I need the metro bundler to run on two different ports.
But it's about the same repo, so I can't change all the occurrences of 8081.
Also, I can't change manually the port using devtools in iOS Simulator, because it's for e2e tests with Detox, automatics.
I saw here and there that the use of RCT_METRO_PORT could work, but until now I don't success...
So here is the simple question: how do we make use of RCT_METRO_PORT so that the metro bundler runs on another port than 8081, using either a .env file or an env variable in package.json scripts?
[EDIT]: my question is not only for react native run ios but also for building release, like this script set -o pipefail && xcodebuild -workspace ios/myapp.xcworkspace -configuration Debug -scheme myapp -destination name="iPhone 12 Pro" -derivedDataPath ios/build > /dev/null
Based on this answer you must change the default port from environment variable, there are three way
First: (local env): Install react-native-dotenv, and configure it on your babel config file. Then add a .env file in the root folder of your project and write RCT_METRO_PORT=8590. (8590 is sample for alternative port number)
Second: (global env): Go to your bash/zsh rc file and export the environment variable with number 8590 for example:
export RCT_METRO_PORT=8590
hint: if your OS is windows, for second option follow this answer
Third: (inline env): For each of actions you should use --port 8590:
Metro: yarn start --port 8590
Android: yarn android --port 8590
iOS: yarn ios --port 8590
TEST: run echo $RCT_METRO_PORT in your terminal to test 1st and 2nd way to be ensure your env var is set.
iOS Hint: For the ios folder of your project find the Pods folder and inside the Pods folder seek RCTDefines.h files, there are two of them, inside both of them change the 8081 to 8590.
For connecting to the React Native Debugger press ⌘+t and change the 8081 port to 8590.
this is how you can manage different ports for dev and stage env in package.json
DOCS
"scripts": {
"android:dev": "RCT_METRO_PORT=8081 react-native run-android",
"android:stage": "RCT_METRO_PORT=9091 react-native run-android",
"ios:dev": "RCT_METRO_PORT=8081 react-native run-ios",
"ios:stage": "RCT_METRO_PORT=9091 react-native run-ios",
"start:dev": "react-native start --port 8081",
"start:stage": "react-native start --port 9091",
"build:dev": "export RCT_METRO_PORT=8081 && set -o pipefail && xcodebuild -workspace ios/myapp.xcworkspace -configuration Debug -scheme myapp -destination name=\"iPhone 12 Pro\" -derivedDataPath ios/build > /dev/null",
"build:stage": "export RCT_METRO_PORT=9091 && set -o pipefail && xcodebuild -workspace ios/myapp.xcworkspace -configuration Debug -scheme myapp -destination name=\"iPhone 12 Pro\" -derivedDataPath ios/build > /dev/null",
}
OR
"scripts": {
"android:dev": "react-native run-android --port 8081",
"android:stage": "react-native run-android --port 9091",
"ios:dev": "react-native run-ios --port 8081",
"ios:stage": "react-native run-ios --port 9091",
"start:dev": "react-native start --port 8081",
"start:stage": "react-native start --port 9091",
"build:dev": "export RCT_METRO_PORT=8081 && set -o pipefail && xcodebuild -workspace ios/myapp.xcworkspace -configuration Debug -scheme myapp -destination name=\"iPhone 12 Pro\" -derivedDataPath ios/build > /dev/null",
"build:stage": "export RCT_METRO_PORT=9091 && set -o pipefail && xcodebuild -workspace ios/myapp.xcworkspace -configuration Debug -scheme myapp -destination name=\"iPhone 12 Pro\" -derivedDataPath ios/build > /dev/null",
}
Question: For this pull request, the tests do not pass on CircleCI but the tests pass locally. Why?
The CircleCI test output shows failures for all FBSnapshotTestCase tests. For example:
✗ testAdjustsFontSizeToFitWidth, ((comparisonSuccess__) is true) failed - Snapshot comparison failed: Error Domain=FBSnapshotTestControllerErrorDomain Code=1 "Unable to load reference image." UserInfo=0x7f85f36b0a50 {NSLocalizedFailureReason=Reference image not found. You need to run the test in record mode, NSLocalizedDescription=Unable to load reference image., FBReferenceImageFilePathKey=/Users/distiller/TTTAttributedLabel/Example/TTTAttributedLabelTests/ReferenceImages_32/TTTAttributedLabelTests/testAdjustsFontSizeToFitWidth#2x.png}
[…]
✗ testAttributedTruncationToken, ((comparisonSuccess__) is true) failed - Snapshot comparison failed: Error Domain=FBSnapshotTestControllerErrorDomain Code=1 "Unable to load reference image." UserInfo=0x7f85f35b06d0 {NSLocalizedFailureReason=Reference image not found. You need to run the test in record mode, NSLocalizedDescription=Unable to load reference image., FBReferenceImageFilePathKey=/Users/distiller/TTTAttributedLabel/Example/TTTAttributedLabelTests/ReferenceImages_32/TTTAttributedLabelTests/testAttributedTruncationToken#2x.png}
However, the same tests pass locally:
On CircleCI the tests use the ReferenceImages_32 directory, which does not exist:
/Users/distiller/TTTAttributedLabel/Example/TTTAttributedLabelTests/ReferenceImages_32/TTTAttributedLabelTests/testAdjustsFontSizeToFitWidth#2x.png
However, the images do exist in ReferenceImages_64. I expect the _64 directory to be used because the circle.yml file specifies to use the iPhone 6 simulator:
dependencies:
pre:
- xcrun instruments -w "iPhone 6 (8.3 Simulator)" || exit 0
override:
- sudo gem install cocoapods xcpretty obcd -N
- pod install --project-directory=Example
test:
override:
- set -o pipefail && xcodebuild -workspace 'Example/Espressos.xcworkspace' -scheme 'Espressos'
-sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 6"
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES clean test | xcpretty -c
--report junit --output ${CIRCLE_TEST_REPORTS}/junit.xml
What causes this?
How can I get the tests passing on CircleCI?
Possibly related: this FBSnapshotTestCase issue
Have you tried running the build without the cache? This often fixes these kinds of issues for me. To build without cache, just click the button at the top right.
I've been trying to figure out how to run our Unit Tests from the command line, so that we can automate them.
I'm using XCode 4.5.2, and building an IOS application.
First I tried using this:
xcodebuild -target "Unit Tests" -configuration "Debug (test syncserver)" -sdk iphonesimulator6.0 clean build TEST_AFTER_BUILD=YES
That would run the compile, but the test didn't run.
So, after reading other solutions around here, I installed ios-sim and setup my target to run this script afterward:
(Note that I had to replace occurences of "TEST_HOST" with "CODESIGNING_FOLDER_PATH" as TEST_HOST doesn't seem to exist in my builds.)
#!/bin/bash
if [ "$RUN_UNIT_TEST_WITH_IOS_SIM" = "YES" ]; then
test_bundle_path="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.$WRAPPER_EXTENSION"
echo ios-sim launch "$(dirname "$CODESIGNING_FOLDER_PATH")" --setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection --setenv XCInjectBundle="$test_bundle_path" --setenv XCInjectBundleInto="$CODESIGNING_FOLDER_PATH" --args -SenTest All "$test_bundle_path"
ios-sim launch "$(dirname "$CODESIGNING_FOLDER_PATH")" --setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection --setenv XCInjectBundle="$test_bundle_path" --setenv XCInjectBundleInto="$CODESIGNING_FOLDER_PATH" --args -SenTest All "$test_bundle_path"
echo "Finished running tests with ios-sim"
else
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
fi
Now, when I run the same xcodebuild command as before, I get this:
/bin/sh -c
"\"/Users/johnlussmyer/tu/ondeck/OnDeck/build/OnDeck.build/Debug (test
syncserver)-iphonesimulator/Unit
Tests.build/Script-4CECE52812D5043F0063EC6A.sh\"" ios-sim launch
/Users/johnlussmyer/tu/ondeck/OnDeck/build/Debug (test
syncserver)-iphonesimulator --setenv
DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection
--setenv XCInjectBundle=/Users/johnlussmyer/tu/ondeck/OnDeck/build/Debug (test
syncserver)-iphonesimulator/UnitTests.app --setenv
XCInjectBundleInto=/Users/johnlussmyer/tu/ondeck/OnDeck/build/Debug
(test syncserver)-iphonesimulator/UnitTests.app --args -SenTest All
/Users/johnlussmyer/tu/ondeck/OnDeck/build/Debug (test
syncserver)-iphonesimulator/UnitTests.app [DEBUG] Session could not be
started: Error Domain=DTiPhoneSimulatorErrorDomain Code=1 "Unknown
error." UserInfo=0x7fcf04b03190 {NSLocalizedDescription=Unknown
error., DTiPhoneSimulatorUnderlyingErrorCodeKey=-1} Finished running
tests with ios-sim
Any suggestions on what to try next?
From the log, it seems you have several wrong settings. The correct syntax is:
ios-sim launch YourApp.app
--setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection
--setenv XCInjectBundle=YourTest.octest
--setenv XCInjectBundleInto=YourApp.app/YourApp
--args -SenTest All YourTest.octest
You could see that
the app path is incorrect after launch command
XCInjectBundle should be your octest instead of app
XCInjectBundleInto should be your app binary path instead of app folder
The last argument should also be your octest
If you can't see TEST_HOST in your environment variables, you may want to go through them to find some propers ones to make your bash script correct.
A bit old question.. but I fall here some similar question.
My two cents for OSX/ iOS (tested under iOS13 / Catalina / Xcode 11). (hope it can help someone..)
func underXCTest()->Bool{
let environment = ProcessInfo.processInfo.environment
if let _ = environment["XCInjectBundleInto"]{
return true
}
return false
}
Under testing return false.