Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CocoaPods-based RNTesterPods for iOS tests #25416

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
126 changes: 30 additions & 96 deletions .circleci/config.yml
Expand Up @@ -34,7 +34,7 @@ executors:
reactnativeios:
<<: *defaults
macos:
xcode: "10.2.0"
xcode: "10.2.1"

# -------------------------
# COMMANDS
Expand Down Expand Up @@ -117,6 +117,21 @@ commands:
- ~/Library/Caches/Homebrew
key: v1-brew

with_pods_cache_span:
parameters:
steps:
type: steps
steps:
- restore_cache:
keys:
- v1-pods-{{ checksum "RNTester/Podfile.lock" }}
- v1-pods-
- steps: << parameters.steps >>
- save_cache:
paths:
- RNTester/Pods
key: v1-pods-{{ checksum "RNTester/Podfile.lock" }}

download_gradle_dependencies:
steps:
- restore_cache:
Expand Down Expand Up @@ -294,111 +309,31 @@ jobs:
- setup_artifacts
- run_yarn

- run: |
cd RNTester
bundle check || bundle install
- run:
name: Print Xcode environment
command: xcodebuild -version
name: Boot iPhone Simulator
command: source scripts/.tests.env && xcrun simctl boot "$IOS_DEVICE" || true

- run:
name: List available devices
command: instruments -s devices
name: Fetch CocoaPods Specs
command: |
curl https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash -s cf

- run:
name: Boot iOS Simulator
command: source scripts/.tests.env && xcrun simctl boot "$IOS_DEVICE" || true
- with_pods_cache_span:
steps:
- run:
name: Generate RNTesterPods Workspace
command: cd RNTester && pod install --verbose

- with_brew_cache_span:
steps:
- brew_install:
package: watchman
- run: touch .watchmanconfig

- run:
name: Start Metro packager
command: yarn start --max-workers=1 || echo "Can't start packager automatically"
background: true

- run:
name: Start WebSocket test server
command: open "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically"
background: true

- run:
name: Verify RNTester can be built
command: |
source ./scripts/.tests.env
xcodebuild \
-project RNTester/RNTester.xcodeproj \
-scheme RNTester \
-sdk iphonesimulator \
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
-UseModernBuildSystem=NO \
build | \
xcpretty --report junit --output "$REPORTS_DIR/junit/ios_buiild/results.xml" && \
exit "${PIPESTATUS[0]}"

- run:
name: Wait for Metro packager
command: |
max_attempts=60
attempt_num=1
until curl -s http://localhost:8081/status | grep "packager-status:running" -q; do
if (( attempt_num == max_attempts )); then
echo "Packager did not respond in time. No more attempts left."
exit 1
else
(( attempt_num++ ))
echo "Packager did not respond. Retrying for attempt number $attempt_num..."
sleep 1
fi
done
echo "Packager is ready!"

- run:
name: Preload the RNTesterApp bundles
command: |
curl --silent 'http://localhost:8081/RNTester/js/RNTesterApp.ios.bundle?platform=ios&dev=true' --output /dev/null
curl --silent 'http://localhost:8081/RNTester/js/RNTesterApp.ios.bundle?platform=ios&dev=true&minify=false' --output /dev/null
curl --silent 'http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true' --output /dev/null
curl --silent 'http://localhost:8081/IntegrationTests/RCTRootViewIntegrationTestApp.bundle?platform=ios&dev=true' --output /dev/null

- run:
name: Run RNTester Unit Tests
command: |
source ./scripts/.tests.env
xcodebuild \
-project RNTester/RNTester.xcodeproj \
-scheme RNTester \
-sdk iphonesimulator \
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
-UseModernBuildSystem=NO \
-only-testing:RNTesterUnitTests \
build test | \
xcpretty --report junit --output "$REPORTS_DIR/junit/ios_unit_tests/results.xml" && \
exit "${PIPESTATUS[0]}"

- run:
name: Run RNTester Integration Tests
command: |
source ./scripts/.tests.env
xcodebuild \
-project RNTester/RNTester.xcodeproj \
-scheme RNTester \
-sdk iphonesimulator \
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
-UseModernBuildSystem=NO \
-only-testing:RNTesterIntegrationTests \
build test | \
xcpretty --report junit --output "$REPORTS_DIR/junit/ios_integration_tests/results.xml" && \
exit "${PIPESTATUS[0]}"

- run:
name: Stop Metro packager and WebSocket test server
command: |
# kill whatever is occupying port 8081 (packager)
lsof -i tcp:8081 | awk 'NR!=1 {print $2}' | xargs kill
# kill whatever is occupying port 5555 (web socket server)
lsof -i tcp:5555 | awk 'NR!=1 {print $2}' | xargs kill

- run: yarn test-ios
- store_test_results:
path: ~/reports/junit

Expand Down Expand Up @@ -431,7 +366,6 @@ jobs:
package: applesimutils
- brew_install:
package: watchman

# Configure Watchman
- run: touch .watchmanconfig

Expand Down
1 change: 0 additions & 1 deletion RNTester/.gitignore

This file was deleted.

4 changes: 4 additions & 0 deletions RNTester/Gemfile
@@ -0,0 +1,4 @@
# Gemfile
source 'https://rubygems.org'

gem 'cocoapods', '= 1.7.1'
22 changes: 21 additions & 1 deletion RNTester/Podfile
Expand Up @@ -2,7 +2,7 @@ platform :ios, '9.0'

require_relative '../scripts/autolink-ios'

target 'RNTester' do
def pods()
# Uncomment for Swift
# use_frameworks!

Expand All @@ -21,3 +21,23 @@ target 'RNTester' do
# To use fabric: add `fabric_enabled` option to the use_react_native method above, like below
# use_react_native!(path: "..", turbo_modules_enabled: true, fabric_enabled: true)
end

target 'RNTester' do
pods()
end

target 'RNTesterUnitTests' do
pods()
pod 'React-RCTTest', :path => "RCTTest"
end

target 'RNTesterIntegrationTests' do
pods()
pod 'React-RCTTest', :path => "RCTTest"
end

post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end
13 changes: 2 additions & 11 deletions RNTester/README.md
Expand Up @@ -14,18 +14,9 @@ Before running the app, make sure you ran:

Both macOS and Xcode are required.

- Open `RNTester/RNTester.xcodeproj` in Xcode
- Hit the Run button

See [Running on device](https://facebook.github.io/react-native/docs/running-on-device.html) if you want to use a physical device.

### Running on iOS with CocoaPods

Similar to above, you can build the app via Xcode with help of CocoaPods.

- Install [CocoaPods](http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#3-install-cocoapods)
- Install CocoaPods. We installing CocoaPods using [Homebrew](http://brew.sh/): `brew install cocoapods`
- Run `cd RNTester; pod install`
- Open the generated `RNTesterPods.xcworkspace` (this is not checked in). Do not open `RNTesterPods.xcodeproj` directly.
- Open the generated `RNTesterPods.xcworkspace`. This is not checked in, as it is generated by CocoaPods. Do not open `RNTesterPods.xcodeproj` directly.

### Running on Android

Expand Down
4 changes: 1 addition & 3 deletions RNTester/RNTesterIntegrationTests/Info.plist
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -16,8 +16,6 @@
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down
Expand Up @@ -9,10 +9,17 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#if (defined(COCOAPODS))
#import <React-RCTTest/React/RCTTestRunner.h>
#import <React-Core/React/RCTEventDispatcher.h>
#import <React-Core/React/RCTRootView.h>
#import <React-Core/React/RCTRootViewDelegate.h>
#else
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTRootView.h>
#import <React/RCTRootViewDelegate.h>
#endif

#define RCT_TEST_DATA_CONFIGURATION_BLOCK(appName, testType, input, block) \
- (void)DISABLED_test##appName##_##testType##_##input \
Expand Down
5 changes: 5 additions & 0 deletions RNTester/RNTesterIntegrationTests/RNTesterIntegrationTests.m
Expand Up @@ -8,7 +8,11 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#if (defined(COCOAPODS))
#import <React-RCTTest/React/RCTTestRunner.h>
#else
#import <RCTTest/RCTTestRunner.h>
#endif

#define RCT_TEST(name) \
- (void)test##name \
Expand Down Expand Up @@ -76,3 +80,4 @@ - (void)testTheTester_waitOneFrame
RCT_TEST(AccessibilityManagerTest)

@end

4 changes: 4 additions & 0 deletions RNTester/RNTesterIntegrationTests/RNTesterSnapshotTests.m
Expand Up @@ -9,7 +9,11 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#if (defined(COCOAPODS))
#import <React-RCTTest/React/RCTTestRunner.h>
#else
#import <RCTTest/RCTTestRunner.h>
#endif

@interface RNTesterSnapshotTests : XCTestCase
{
Expand Down