Skip to content

Commit ee10c4e

Browse files
authored
Use test specs for Functions unit tests (#1864)
1 parent 032f0bf commit ee10c4e

File tree

11 files changed

+73
-39
lines changed

11 files changed

+73
-39
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ Ninja
8181

8282
# Visual Studio
8383
/.vs
84+
85+
# CocoaPods generate
86+
gen/

.travis.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ jobs:
3535
script:
3636
- travis_retry ./scripts/if_changed.sh ./scripts/build.sh $PROJECT $PLATFORM
3737

38+
- stage: test
39+
env:
40+
- PROJECT=Functions PLATFORM=iOS METHOD=pod-lib-lint
41+
before_install:
42+
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
43+
script:
44+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseFunctions.podspec
45+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseFunctions.podspec --use-libraries
46+
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseFunctions.podspec --use-modular-headers
47+
3848
- stage: test
3949
env:
4050
- PROJECT=InAppMessaging PLATFORM=iOS METHOD=xcodebuild
@@ -68,7 +78,6 @@ jobs:
6878
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInstanceID.podspec
6979
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseMessaging.podspec
7080
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseStorage.podspec
71-
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseFunctions.podspec
7281
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInAppMessaging.podspec
7382
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.sh FirebaseInAppMessagingDisplay.podspec
7483

@@ -100,7 +109,6 @@ jobs:
100109
# The Protobuf dependency of FirebaseMessaging has warnings with --use-libraries
101110
- travis_retry ./scripts/if_cron.sh ./scripts/pod_lib_lint.sh FirebaseMessaging.podspec --use-libraries --allow-warnings
102111
- travis_retry ./scripts/if_cron.sh ./scripts/pod_lib_lint.sh FirebaseStorage.podspec --use-libraries
103-
- travis_retry ./scripts/if_cron.sh ./scripts/pod_lib_lint.sh FirebaseFunctions.podspec --use-libraries
104112
- travis_retry ./scripts/if_cron.sh ./scripts/pod_lib_lint.sh FirebaseInAppMessaging.podspec --use-libraries
105113
- travis_retry ./scripts/if_cron.sh ./scripts/pod_lib_lint.sh FirebaseInAppMessagingDisplay.podspec --use-libraries
106114

FirebaseFunctions.podspec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ iOS SDK for Cloud Functions for Firebase.
3232
'GCC_C_LANGUAGE_STANDARD' => 'c99',
3333
'GCC_PREPROCESSOR_DEFINITIONS' => 'FIRFunctions_VERSION=' + s.version.to_s
3434
}
35+
36+
s.test_spec 'unit' do |unit_tests|
37+
unit_tests.source_files = 'Functions/Example/Test*/*.[mh]', 'Example/Shared/FIRAuthInteropFake*'
38+
end
39+
40+
s.test_spec 'integration' do |int_tests|
41+
int_tests.source_files = 'Functions/Example/IntegrationTests/*.[mh]',
42+
'Functions/Example/TestUtils/*.[mh]',
43+
'Example/Shared/FIRAuthInteropFake*'
44+
end
3545
end

Functions/Backend/start.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# Sets up a project with the functions CLI and starts a backend to run
1818
# integration tests against.
1919

20+
# Adding the "synchronous" parameter will cause the script to exit
21+
# with the server still running so that other scripts can invoke this
22+
# script followed by subsequent dependent commands.
23+
2024
set -e
2125

2226
# Get the absolute path to the directory containing this script.
@@ -32,7 +36,9 @@ npm install
3236

3337
# Start the server.
3438
FUNCTIONS_BIN="./node_modules/.bin/functions"
35-
"${FUNCTIONS_BIN}" config set projectId functions-integration-test
39+
"${FUNCTIONS_BIN}" config set projectId functions-integration-test <<-!
40+
myproject
41+
!
3642
"${FUNCTIONS_BIN}" config set supervisorPort 5005
3743
"${FUNCTIONS_BIN}" config set region us-central1
3844
"${FUNCTIONS_BIN}" config set verbose true
@@ -49,8 +55,10 @@ FUNCTIONS_BIN="./node_modules/.bin/functions"
4955
"${FUNCTIONS_BIN}" deploy httpErrorTest --trigger-http
5056
"${FUNCTIONS_BIN}" deploy timeoutTest --trigger-http
5157

52-
# Wait for the user to tell us to stop the server.
53-
echo "Functions emulator now running in ${TEMP_DIR}."
54-
read -n 1 -p "*** Press any key to stop the server. ***"
55-
echo "\nStopping the emulator..."
56-
"${FUNCTIONS_BIN}" stop
58+
if [ "$1" != "synchronous" ]; then
59+
# Wait for the user to tell us to stop the server.
60+
echo "Functions emulator now running in ${TEMP_DIR}."
61+
read -n 1 -p "*** Press any key to stop the server. ***"
62+
echo "\nStopping the emulator..."
63+
"${FUNCTIONS_BIN}" stop
64+
fi

Functions/Example/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target 'FirebaseFunctions_Example' do
55

66
pod 'FirebaseAuthInterop', :path => '../../'
77
pod 'FirebaseCore', :path => '../../'
8-
pod 'FirebaseFunctions', :path => '../../'
8+
pod 'FirebaseFunctions', :path => '../../', :testspecs => ['unit']
99
pod 'GoogleUtilities', :path => '../../'
1010

1111
target 'FirebaseFunctions_Tests' do

Functions/README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@
55
Follow the subsequent instructions to develop, debug, unit test, and
66
integration test FirebaseFunctions:
77

8-
```
9-
$ git clone [email protected]:firebase/firebase-ios-sdk.git
10-
$ cd firebase-ios-sdk/Functions/Example
11-
$ pod update
12-
$ open FirebaseFunctions.xcworkspace
13-
```
8+
### Prereqs
9+
10+
- At least CocoaPods 1.6.0
11+
- Install [cocoapods-generate](https://github.com/square/cocoapods-generate)
12+
13+
### To Develop
14+
15+
- Run `pod gen FirebaseFunctions.podspec`
16+
- `open gen/FirebaseFunctions/FirebaseFunctions.xcworkspace`
17+
18+
OR these two commands can be combined with
19+
20+
- `pod gen FirebaseFunctions.podspec --auto-open --gen-directory="gen" --clean`
21+
22+
You're now in an Xcode workspace generate for building, debugging and
23+
testing the FirebaseFunctions CocoaPod.
1424

1525
### Running Unit Tests
1626

17-
Choose the FirebaseFunctions_Tests scheme and press Command-u.
27+
Choose the FirebaseFunctions-Unit-unit scheme and press Command-u.
1828

1929
## Running Integration Tests
2030

@@ -29,5 +39,5 @@ for them to talk to.
2939
You can put anything you like. It will be ignored.
3040
3. Create the workspace in Functions/Example with `pod install`.
3141
4. `open FirebaseFunctions.xcworkspace`
32-
5. Choose the FirebaseFunctions_IntegrationTests scheme and press Command-u.
42+
5. Choose the FirebaseFunctions-Unit-integration scheme and press Command-u.
3343
6. When you are finished, you can press any key to stop the backend.

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
source 'https://rubygems.org'
44

55
gem 'cocoapods', "=1.6.1"
6+
gem 'cocoapods-generate'

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ GEM
3434
nap (~> 1.0)
3535
cocoapods-deintegrate (1.0.3)
3636
cocoapods-downloader (1.2.2)
37+
cocoapods-generate (1.3.1)
3738
cocoapods-plugins (1.0.0)
3839
nap
3940
cocoapods-search (1.0.0)
@@ -71,6 +72,7 @@ PLATFORMS
7172

7273
DEPENDENCIES
7374
cocoapods (= 1.6.1)
75+
cocoapods-generate
7476

7577
BUNDLED WITH
7678
1.16.6

scripts/build.sh

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,6 @@ case "$product-$method-$platform" in
185185
test
186186

187187
if [[ $platform == 'iOS' ]]; then
188-
RunXcodebuild \
189-
-workspace 'Functions/Example/FirebaseFunctions.xcworkspace' \
190-
-scheme "FirebaseFunctions_Tests" \
191-
"${xcb_flags[@]}" \
192-
build \
193-
test
194-
195188
# Run integration tests (not allowed on PRs)
196189
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
197190
RunXcodebuild \
@@ -227,17 +220,6 @@ case "$product-$method-$platform" in
227220
"${xcb_flags[@]}" \
228221
build \
229222
test
230-
231-
cd Functions/Example
232-
sed -i -e 's/use_frameworks/\#use_frameworks/' Podfile
233-
pod update --no-repo-update
234-
cd ../..
235-
RunXcodebuild \
236-
-workspace 'Functions/Example/FirebaseFunctions.xcworkspace' \
237-
-scheme "FirebaseFunctions_Tests" \
238-
"${xcb_flags[@]}" \
239-
build \
240-
test
241223
fi
242224
;;
243225

scripts/if_changed.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,28 @@ else
4747
case "$PROJECT-$METHOD" in
4848
Firebase-pod-lib-lint) # Combines Firebase-* and InAppMessaging*
4949
check_changes '^(Firebase/Auth|Firebase/Core|Firebase/Database|Firebase/DynamicLinks|'\
50-
'Firebase/Messaging|Firebase/Storage|Functions|GoogleUtilities|Interop|Example|'\
50+
'Firebase/Messaging|Firebase/Storage|GoogleUtilities|Interop|Example|'\
5151
'FirebaseAnalyticsIntop.podspec|FirebaseAuth.podspec|FirebaseAuthInterop.podspec|'\
5252
'FirebaseCore.podspec|FirebaseDatabase.podspec|FirebaseDynamicLinks.podspec|'\
53-
'FirebaseFunctions.podspec|FirebaseMessaging.podspec|FirebaseStorage.podspec|'\
53+
'FirebaseMessaging.podspec|FirebaseStorage.podspec|'\
5454
'FirebaseStorage.podspec|Firebase/InAppMessagingDisplay|InAppMessagingDisplay|'\
5555
'InAppMessaging|Firebase/InAppMessaging|'\
5656
'FirebaseInAppMessaging.podspec|FirebaseInAppMessagingDisplay.podspec)'
5757
;;
5858

5959
Firebase-*)
6060
check_changes '^(Firebase/Auth|Firebase/Core|Firebase/Database|Firebase/DynamicLinks|'\
61-
'Firebase/Messaging|Firebase/Storage|Functions|GoogleUtilities|Interop|Example|'\
61+
'Firebase/Messaging|Firebase/Storage|GoogleUtilities|Interop|Example|'\
6262
'FirebaseAnalyticsIntop.podspec|FirebaseAuth.podspec|FirebaseAuthInterop.podspec|'\
6363
'FirebaseCore.podspec|FirebaseDatabase.podspec|FirebaseDynamicLinks.podspec|'\
64-
'FirebaseFunctions.podspec|FirebaseMessaging.podspec|FirebaseStorage.podspec|'\
64+
'FirebaseMessaging.podspec|FirebaseStorage.podspec|'\
6565
'FirebaseStorage.podspec)'
6666
;;
6767

68+
Functions-*)
69+
check_changes '^(Firebase/Core|Functions|GoogleUtilities|FirebaseFunctions.podspec)'
70+
;;
71+
6872
InAppMessaging-*)
6973
check_changes '^(Firebase/InAppMessagingDisplay|InAppMessagingDisplay|InAppMessaging|'\
7074
'Firebase/InAppMessaging)'

scripts/install_prereqs.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ case "$PROJECT-$PLATFORM-$METHOD" in
5555
bundle exec pod install --project-directory=GoogleUtilities/Example
5656
;;
5757

58+
Functions-*)
59+
bundle exec pod repo update
60+
# Start server for Functions integration tests.
61+
./Functions/Backend/start.sh synchronous
62+
;;
63+
5864
InAppMessaging-iOS-xcodebuild)
5965
gem install xcpretty
6066
bundle exec pod install --project-directory=InAppMessagingDisplay/Example --repo-update

0 commit comments

Comments
 (0)