This guide contains the steps required to contribute to the development of this project.
- Setting Up a Development Environment
- Updating Dependency Versions
- Configuring CircleCI
- Running Unit Tests On Devices
- Running Integration Tests
- Making an Example
This project runs on Apple's Metal rendering framework. Prerequisites for running the test app in simulators:
- macOS 10.15 or later
- Xcode 12.5.1+
This project:
-
requires a valid ~/.netrc file to fetch dependencies.
-
reads a Mapbox access token from a file at
~/mapbox
to enable tests and apps to access Mapbox APIs. -
uses SwiftLint to enforce a style guide. Install it with
brew install swiftlint
and check for lint by runningswiftlint
in the root of the repository. -
uses Swift Package Manager to manage dependencies for development. Cocapods is supported for consuming the SDK.
-
uses secret-shield to help block secrets such as access tokens from being exposed. Setup
secret-shield
by running:npm install -g @mapbox/secret-shield scripts/install-pre-commit/install-pre-commit.sh
-
uses CircleCI and Firebase Test Lab for continuous integration.
Clone the git repository:
git clone [email protected]:mapbox/mapbox-maps-ios.git && cd mapbox-maps-ios
Open Apps/Apps.xcworkspace
and build the MapboxMaps
target.
In order to use the debug app, run the DebugApp
scheme.
- Update the dependency versions in
Package.swift
- Open
Package.swift
in Xcode and resolve dependencies. This updatesPackage.resolved
. Close that Xcode workspace. - Open
Apps/Apps.xcworkspace
in Xcode and resolve dependencies. This updates a differentPackage.resolved
file in theApps.workspace
bundle. Close that Xcode workspace. - Update the dependency versions in
MapboxMaps.podspec
- Update the dependency versions in
scripts/release/packager/versions.json
You can run make validate
to ensure you've formatted the changes to the
CircleCI config file correctly. This make target will install the
CircleCI command line interface to
validate .circleci/config.yml
, and run circleci config validate
.
To run unit tests on an iOS device there are two options:
-
Run locally:
- Install xcodegen.
- Run
$ xcodegen
in the root of the repo. - Open the resulting
MapboxMaps.xcodeproj
. - Test the
MapboxTestHost
scheme.
-
Run in CI:
- Open the optional-tests workflow for your branch in CircleCI
- Approve the
run-tests?
job to trigger running unit tests on Firebase Test Lab - Approve the
run-examples-tests?
job to trigger running examples tests on Firebase Test Lab
Integration tests typically require a Metal device, so these tests can only run locally and on Firebase Test Lab. They are skipped when running on CircleCI inside of a VM and when running on simulators < iOS 13 (iOS 13+ has a simulated Metal device.)
There is a host application, so MapViewIntegrationTestCase
fetches the
existing window and view controller before adding the MapView to it.
- These tests can be run on devices.
- Tests will be skipped on simulators < iOS 13
There is no host application, so MapViewIntegrationTestCase
creates its
own UIWindow
and root view controller, before adding the MapView to it.
- These tests cannot be run on devices.
- Tests will be skipped on simulators < iOS 13
- Tests will be skipped entirely on CircleCI because of the VM (no Metal).
-
IntegrationTestCase
is a base class that fetches the access token for use in tests. It checks for the token in the following locations and uses the first one that it finds:-
UserDefaults
under the keyMBXAccessToken
. This allows setting a value when running tests from the command line. -
Info.plist
under the keyMBXAccessToken
. The value for this key is populated automatically when running tests viaMapboxTestHost
if you have adeveloper.xcconfig
file in the root of the repo that looks like:MAPBOX_ACCESS_TOKEN = pk.myaccesstoken
-
a resource in the test bundle named MapboxAccessToken. This file is generated at build time via a pre-action on the scheme when running tests using
MapboxMaps
. The pre-action pulls the token from~/mapbox
or~/.mapbox
.
-
-
MapViewIntegrationTestCase
subclasses the above, and sets theMapView
. Closures are used to expose key map events to subclasses. Please don't add tests to this class. -
ExampleIntegrationTest
is an example of using the above, that sets a style then waits for the load to finish.
- Check out this doc to get more information about adding examples to our project.