Skip to content

Commit 9ece5bd

Browse files
hramosfacebook-github-bot
authored andcommitted
Use CocoaPods-based RNTesterPods for iOS tests (#25416)
Summary: Pull Request resolved: #25416 Use CocoaPods-based RNTesterPods workspace to run iOS unit tests and integration tests. This is necessary as new iOS projects now use CocoaPods by default. CocoaPods also powers the new package auto-linking feature. In order to provide test coverage for this new default configuration, our iOS tests are being migrated to use a CocoaPods-managed RNTester workspace. This applies to both Circle CI, and Sandcastle. Changelog: [iOS] [Changed] - Use RNTesterPods for iOS Tests Reviewed By: fkgozali Differential Revision: D16052466 fbshipit-source-id: 724b0c51008882d3c06a9074693fe23e74abe86b
1 parent e7a0979 commit 9ece5bd

32 files changed

+1098
-296
lines changed

.circleci/config.yml

Lines changed: 30 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ executors:
3434
reactnativeios:
3535
<<: *defaults
3636
macos:
37-
xcode: "10.2.0"
37+
xcode: "10.2.1"
3838

3939
# -------------------------
4040
# COMMANDS
@@ -117,6 +117,21 @@ commands:
117117
- ~/Library/Caches/Homebrew
118118
key: v1-brew
119119

120+
with_pods_cache_span:
121+
parameters:
122+
steps:
123+
type: steps
124+
steps:
125+
- restore_cache:
126+
keys:
127+
- v1-pods-{{ checksum "RNTester/Podfile.lock" }}
128+
- v1-pods-
129+
- steps: << parameters.steps >>
130+
- save_cache:
131+
paths:
132+
- RNTester/Pods
133+
key: v1-pods-{{ checksum "RNTester/Podfile.lock" }}
134+
120135
download_gradle_dependencies:
121136
steps:
122137
- restore_cache:
@@ -294,111 +309,31 @@ jobs:
294309
- setup_artifacts
295310
- run_yarn
296311

312+
- run: |
313+
cd RNTester
314+
bundle check || bundle install
297315
- run:
298-
name: Print Xcode environment
299-
command: xcodebuild -version
316+
name: Boot iPhone Simulator
317+
command: source scripts/.tests.env && xcrun simctl boot "$IOS_DEVICE" || true
300318

301319
- run:
302-
name: List available devices
303-
command: instruments -s devices
320+
name: Fetch CocoaPods Specs
321+
command: |
322+
curl https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash -s cf
304323
305-
- run:
306-
name: Boot iOS Simulator
307-
command: source scripts/.tests.env && xcrun simctl boot "$IOS_DEVICE" || true
324+
- with_pods_cache_span:
325+
steps:
326+
- run:
327+
name: Generate RNTesterPods Workspace
328+
command: cd RNTester && pod install --verbose
308329

309330
- with_brew_cache_span:
310331
steps:
311332
- brew_install:
312333
package: watchman
313334
- run: touch .watchmanconfig
314335

315-
- run:
316-
name: Start Metro packager
317-
command: yarn start --max-workers=1 || echo "Can't start packager automatically"
318-
background: true
319-
320-
- run:
321-
name: Start WebSocket test server
322-
command: open "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically"
323-
background: true
324-
325-
- run:
326-
name: Verify RNTester can be built
327-
command: |
328-
source ./scripts/.tests.env
329-
xcodebuild \
330-
-project RNTester/RNTester.xcodeproj \
331-
-scheme RNTester \
332-
-sdk iphonesimulator \
333-
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
334-
-UseModernBuildSystem=NO \
335-
build | \
336-
xcpretty --report junit --output "$REPORTS_DIR/junit/ios_buiild/results.xml" && \
337-
exit "${PIPESTATUS[0]}"
338-
339-
- run:
340-
name: Wait for Metro packager
341-
command: |
342-
max_attempts=60
343-
attempt_num=1
344-
until curl -s http://localhost:8081/status | grep "packager-status:running" -q; do
345-
if (( attempt_num == max_attempts )); then
346-
echo "Packager did not respond in time. No more attempts left."
347-
exit 1
348-
else
349-
(( attempt_num++ ))
350-
echo "Packager did not respond. Retrying for attempt number $attempt_num..."
351-
sleep 1
352-
fi
353-
done
354-
echo "Packager is ready!"
355-
356-
- run:
357-
name: Preload the RNTesterApp bundles
358-
command: |
359-
curl --silent 'http://localhost:8081/RNTester/js/RNTesterApp.ios.bundle?platform=ios&dev=true' --output /dev/null
360-
curl --silent 'http://localhost:8081/RNTester/js/RNTesterApp.ios.bundle?platform=ios&dev=true&minify=false' --output /dev/null
361-
curl --silent 'http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true' --output /dev/null
362-
curl --silent 'http://localhost:8081/IntegrationTests/RCTRootViewIntegrationTestApp.bundle?platform=ios&dev=true' --output /dev/null
363-
364-
- run:
365-
name: Run RNTester Unit Tests
366-
command: |
367-
source ./scripts/.tests.env
368-
xcodebuild \
369-
-project RNTester/RNTester.xcodeproj \
370-
-scheme RNTester \
371-
-sdk iphonesimulator \
372-
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
373-
-UseModernBuildSystem=NO \
374-
-only-testing:RNTesterUnitTests \
375-
build test | \
376-
xcpretty --report junit --output "$REPORTS_DIR/junit/ios_unit_tests/results.xml" && \
377-
exit "${PIPESTATUS[0]}"
378-
379-
- run:
380-
name: Run RNTester Integration Tests
381-
command: |
382-
source ./scripts/.tests.env
383-
xcodebuild \
384-
-project RNTester/RNTester.xcodeproj \
385-
-scheme RNTester \
386-
-sdk iphonesimulator \
387-
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
388-
-UseModernBuildSystem=NO \
389-
-only-testing:RNTesterIntegrationTests \
390-
build test | \
391-
xcpretty --report junit --output "$REPORTS_DIR/junit/ios_integration_tests/results.xml" && \
392-
exit "${PIPESTATUS[0]}"
393-
394-
- run:
395-
name: Stop Metro packager and WebSocket test server
396-
command: |
397-
# kill whatever is occupying port 8081 (packager)
398-
lsof -i tcp:8081 | awk 'NR!=1 {print $2}' | xargs kill
399-
# kill whatever is occupying port 5555 (web socket server)
400-
lsof -i tcp:5555 | awk 'NR!=1 {print $2}' | xargs kill
401-
336+
- run: yarn test-ios
402337
- store_test_results:
403338
path: ~/reports/junit
404339

@@ -431,7 +366,6 @@ jobs:
431366
package: applesimutils
432367
- brew_install:
433368
package: watchman
434-
435369
# Configure Watchman
436370
- run: touch .watchmanconfig
437371

RNTester/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

RNTester/Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Gemfile
2+
source 'https://rubygems.org'
3+
4+
gem 'cocoapods', '= 1.7.1'

RNTester/Podfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ platform :ios, '9.0'
22

33
require_relative '../scripts/autolink-ios'
44

5-
target 'RNTester' do
5+
def pods()
66
# Uncomment for Swift
77
# use_frameworks!
88

@@ -21,3 +21,23 @@ target 'RNTester' do
2121
# To use fabric: add `fabric_enabled` option to the use_react_native method above, like below
2222
# use_react_native!(path: "..", turbo_modules_enabled: true, fabric_enabled: true)
2323
end
24+
25+
target 'RNTester' do
26+
pods()
27+
end
28+
29+
target 'RNTesterUnitTests' do
30+
pods()
31+
pod 'React-RCTTest', :path => "RCTTest"
32+
end
33+
34+
target 'RNTesterIntegrationTests' do
35+
pods()
36+
pod 'React-RCTTest', :path => "RCTTest"
37+
end
38+
39+
post_install do |installer|
40+
installer.pods_project.targets.each do |target|
41+
puts target.name
42+
end
43+
end

RNTester/README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,9 @@ Before running the app, make sure you ran:
1414

1515
Both macOS and Xcode are required.
1616

17-
- Open `RNTester/RNTester.xcodeproj` in Xcode
18-
- Hit the Run button
19-
20-
See [Running on device](https://facebook.github.io/react-native/docs/running-on-device.html) if you want to use a physical device.
21-
22-
### Running on iOS with CocoaPods
23-
24-
Similar to above, you can build the app via Xcode with help of CocoaPods.
25-
26-
- Install [CocoaPods](http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#3-install-cocoapods)
17+
- Install CocoaPods. We installing CocoaPods using [Homebrew](http://brew.sh/): `brew install cocoapods`
2718
- Run `cd RNTester; pod install`
28-
- Open the generated `RNTesterPods.xcworkspace` (this is not checked in). Do not open `RNTesterPods.xcodeproj` directly.
19+
- Open the generated `RNTesterPods.xcworkspace`. This is not checked in, as it is generated by CocoaPods. Do not open `RNTesterPods.xcodeproj` directly.
2920

3021
### Running on Android
3122

RNTester/RNTesterIntegrationTests/Info.plist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleDevelopmentRegion</key>
6-
<string>en</string>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
@@ -16,8 +16,6 @@
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
1818
<string>1.0</string>
19-
<key>CFBundleSignature</key>
20-
<string>????</string>
2119
<key>CFBundleVersion</key>
2220
<string>1</string>
2321
</dict>

RNTester/RNTesterIntegrationTests/RCTRootViewIntegrationTests.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
#import <UIKit/UIKit.h>
1010
#import <XCTest/XCTest.h>
1111

12+
#if (defined(COCOAPODS))
13+
#import <React-RCTTest/React/RCTTestRunner.h>
14+
#import <React-Core/React/RCTEventDispatcher.h>
15+
#import <React-Core/React/RCTRootView.h>
16+
#import <React-Core/React/RCTRootViewDelegate.h>
17+
#else
1218
#import <RCTTest/RCTTestRunner.h>
1319
#import <React/RCTEventDispatcher.h>
1420
#import <React/RCTRootView.h>
1521
#import <React/RCTRootViewDelegate.h>
22+
#endif
1623

1724
#define RCT_TEST_DATA_CONFIGURATION_BLOCK(appName, testType, input, block) \
1825
- (void)DISABLED_test##appName##_##testType##_##input \

RNTester/RNTesterIntegrationTests/RNTesterIntegrationTests.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#import <UIKit/UIKit.h>
99
#import <XCTest/XCTest.h>
1010

11+
#if (defined(COCOAPODS))
12+
#import <React-RCTTest/React/RCTTestRunner.h>
13+
#else
1114
#import <RCTTest/RCTTestRunner.h>
15+
#endif
1216

1317
#define RCT_TEST(name) \
1418
- (void)test##name \
@@ -76,3 +80,4 @@ - (void)testTheTester_waitOneFrame
7680
RCT_TEST(AccessibilityManagerTest)
7781

7882
@end
83+

RNTester/RNTesterIntegrationTests/RNTesterSnapshotTests.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
#import <UIKit/UIKit.h>
1010
#import <XCTest/XCTest.h>
1111

12+
#if (defined(COCOAPODS))
13+
#import <React-RCTTest/React/RCTTestRunner.h>
14+
#else
1215
#import <RCTTest/RCTTestRunner.h>
16+
#endif
1317

1418
@interface RNTesterSnapshotTests : XCTestCase
1519
{

0 commit comments

Comments
 (0)