Skip to content

Commit f8c9b58

Browse files
committed
feat: Add IntegrationTests project with Tuist and WireMock setup
- Add Tuist project configuration for IntegrationTests - Add WireMock recorder script for API mocking - Add initial test app implementation - Add proxy mappings for events and identify endpoints - Add README and generation scripts Add NO_OPEN parameter to generate.sh to control Xcode opening - Remove unused configuration variables - Add NO_OPEN parameter (defaults to false) - Conditionally call tuist generate with --no-open flag when NO_OPEN=true - Allows generate.sh to be used both standalone (opens Xcode) and from other scripts (skips Xcode) Refactor run_wiremock_recorder.sh to use detached mode with auto-cleanup - Add generate.sh call at the beginning to build project - Run WireMock in detached mode (-d flag) with named container - Extract logic into three functions: start_wiremock, wait_for_wiremock, stop_wiremock - Add health check waiting for WireMock to be ready (checks admin API) - Implement trap for automatic cleanup on EXIT/INT/TERM signals - Script now stays running until interrupted, ensuring proper container cleanup Add build_application function to run_wiremock_recorder.sh Add reset_simulators function Add find_device, start_simulator and install_application functions Add launch_application and wait_for_app_completion functions Add automatic device selection and test execution flow - Add find_available_device() function to automatically select available iPhone simulator - Add find_app_path() function to locate built application - Add complete test execution flow after WireMock starts - Update device priority list to include iPhone 17 - Move DEVICE_NAME to global variables for dynamic assignment Fix build command to use generic iOS Simulator platform and add quiet mode - Change destination to 'generic/platform=iOS Simulator' to avoid dependency on specific device name - Add -quiet flag to reduce build output verbosity - change order Update README: clarify purpose as API recording tool for testing - Update description to focus on recording API requests for later use in tests - Simplify prerequisites and overview sections - Remove detailed technical sections (Build Process, WireMock Recording, Device Selection, Benefits) - Consolidate troubleshooting into single section for port conflicts - Remove CI/CD integration examples - Update development workflow to emphasize recording purpose Use local SDK sources directly instead of building xcframework - Update Project.swift to use .local(path: '../') package reference - Remove Tuist/Package.swift to allow Xcode to resolve local package - Simplify generate.sh to only generate project (no xcframework build) - Update README to reflect new simpler approach - Remove temp_artifacts directory (no longer needed) Benefits: - No need to rebuild xcframework for every change - Xcode automatically picks up latest source code changes - Much faster development workflow - Simpler and more maintainable approach Remove generate.sh script and update documentation - Delete generate.sh (no longer needed - tuist generate is called directly) - Update README to remove generate.sh section - Simplify available scripts documentation to only show run_wiremock_recorder.sh - add documentation how to use tuist - cleanup .gitignore Remove comment
1 parent 470585f commit f8c9b58

File tree

8 files changed

+433
-0
lines changed

8 files changed

+433
-0
lines changed

IntegrationTests/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Temporary artifacts directory
2+
temp_artifacts/
3+
4+
# Xcode
5+
*.xcworkspace
6+
!*.xcworkspace/contents.xcworkspacedata
7+
!*.xcworkspace/xcshareddata/
8+
IntegrationTests.xcodeproj/
9+
Derived/
10+
11+
# Build artifacts
12+
build/
13+
*.app
14+
15+
# Tuist
16+
.tuist/
17+

IntegrationTests/Project.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import ProjectDescription
2+
3+
let project = Project(
4+
name: "IntegrationTests",
5+
packages: [
6+
.local(path: "../")
7+
],
8+
targets: [
9+
.target(
10+
name: "IntegrationTests",
11+
destinations: .iOS,
12+
product: .app,
13+
bundleId: "com.mparticle.IntegrationTests",
14+
deploymentTargets: .iOS("14.0"),
15+
sources: ["Sources/**"],
16+
dependencies: [
17+
.package(product: "mParticle-Apple-SDK", type: .runtime)
18+
]
19+
)
20+
],
21+
additionalFiles: [
22+
.glob(pattern: "wiremock-recordings/**/*.json"),
23+
.glob(pattern: "*.sh")
24+
]
25+
)

IntegrationTests/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Integration Tests
2+
3+
Tools for recording mParticle Apple SDK API requests using WireMock for later use in integration testing.
4+
5+
## Prerequisites
6+
7+
Before getting started, install Tuist:
8+
9+
```bash
10+
brew install tuist
11+
```
12+
13+
Then generate the Xcode project:
14+
15+
```bash
16+
cd IntegrationTests
17+
tuist generate
18+
```
19+
20+
This will create the `IntegrationTests.xcodeproj` and `IntegrationTests.xcworkspace` files and automatically open them in Xcode.
21+
22+
If you need to edit the Tuist project configuration (`Project.swift`):
23+
24+
```bash
25+
tuist edit
26+
```
27+
28+
This will open a temporary Xcode project for editing Tuist manifest files.
29+
30+
If you encounter any issues with project generation, you can clean the Tuist cache first:
31+
32+
```bash
33+
tuist clean
34+
tuist generate
35+
```
36+
37+
## Overview
38+
39+
This project provides tools for recording mParticle SDK API requests by:
40+
- Generating a test iOS app using Tuist
41+
- Linking directly to local SDK source code
42+
- Running the app in iOS Simulator
43+
- Recording all API traffic with WireMock for later use in testing
44+
45+
The project uses Tuist with `.local(path: "../")` package reference, which allows Xcode to resolve the local SDK package and use source files directly, automatically picking up your latest code changes.
46+
47+
## Available Scripts
48+
49+
### `run_wiremock_recorder.sh` - Record API Requests for Testing
50+
51+
Records all mParticle SDK API requests using WireMock for later use in integration testing.
52+
53+
```bash
54+
./run_wiremock_recorder.sh
55+
```
56+
57+
**What it does:**
58+
1. Generates Tuist project with local SDK sources
59+
2. Builds the integration test application
60+
3. Finds and resets iOS Simulators
61+
4. Automatically selects available iPhone simulator (iPhone 17/16/15 priority)
62+
5. Starts simulator
63+
6. Installs test application
64+
7. Starts WireMock in recording mode
65+
8. Launches test application
66+
9. Records all API traffic to mapping files
67+
10. Waits for application completion
68+
11. Stops WireMock and shows results
69+
70+
**Recorded Files:**
71+
- `wiremock-recordings/mappings/*.json` - API request/response mappings
72+
- `wiremock-recordings/__files/*` - Response body files
73+
74+
## Troubleshooting
75+
76+
### Port Already in Use / No Recordings Created
77+
78+
If you see "port already allocated" errors or if no API requests were recorded, it's likely that the ports (8080 and 443) where WireMock should be running are already occupied by another container or application.
79+
80+
Check what's running on the ports:
81+
82+
```bash
83+
# Check running Docker containers
84+
docker ps
85+
86+
# Check what's using port 443
87+
lsof -i :443
88+
89+
# Check what's using port 8080
90+
lsof -i :8080
91+
```
92+
93+
Stop any conflicting Docker containers:
94+
95+
```bash
96+
docker stop <container-name>
97+
docker rm <container-name>
98+
```
99+
100+
If another application is using the ports, terminate it before running the script.
101+
102+
## Development Workflow
103+
104+
1. Make changes to SDK source code
105+
2. Run `./run_wiremock_recorder.sh`
106+
3. Script automatically uses your latest changes, runs the app, and records API traffic
107+
4. Review recorded mappings in `wiremock-recordings/`
108+
5. Commit mappings to document expected API behavior
109+
110+
**Note:** No need to rebuild the SDK separately - the project links directly to source files and automatically picks up your changes!
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// main.swift
3+
// IntegrationTests
4+
//
5+
// Created by Denis Chilik on 11/4/25.
6+
//
7+
8+
import Foundation
9+
import mParticle_Apple_SDK
10+
11+
12+
var options = MParticleOptions(
13+
key: "", // Put your key
14+
secret: "" // Put your secret
15+
)
16+
17+
var identityRequest = MPIdentityApiRequest.withEmptyUser()
18+
identityRequest.email = "foo@example.com";
19+
identityRequest.customerId = "123456";
20+
options.identifyRequest = identityRequest;
21+
22+
options.onIdentifyComplete = { apiResult, error in
23+
if let apiResult {
24+
apiResult.user.setUserAttribute("example attribute key", value: "example attribute value")
25+
}
26+
}
27+
options.logLevel = .verbose
28+
29+
var networkOptions = MPNetworkOptions()
30+
networkOptions.configHost = "127.0.0.1"; // config2.mparticle.com
31+
networkOptions.eventsHost = "127.0.0.1"; // nativesdks.mparticle.com
32+
networkOptions.identityHost = "127.0.0.1"; // identity.mparticle.com
33+
networkOptions.pinningDisabled = true;
34+
35+
options.networkOptions = networkOptions;
36+
let mparticle = MParticle.sharedInstance()
37+
mparticle.start(with: options)
38+
39+
sleep(1)
40+
41+
mparticle.logEvent("Simple Event Name", eventType: .other, eventInfo: ["SimpleKey": "SimpleValue"])
42+
43+
sleep(7)

IntegrationTests/Tuist.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ProjectDescription
2+
3+
let tuist = Tuist(project: .tuist())

0 commit comments

Comments
 (0)