|
2 | 2 |
|
3 | 3 | default_platform(:ios) |
4 | 4 |
|
5 | | -IOS_VERSION = '15.0' |
6 | | -TEST_DEVICES = ['iPhone 11'].freeze |
| 5 | +TEST_RUNTIME = 'iOS 14.0' |
| 6 | +TEST_DEVICE = 'iPhone 11' |
7 | 7 |
|
8 | 8 | platform :ios do |
9 | 9 | desc 'Builds the project and runs tests' |
10 | 10 | lane :test do |
| 11 | + device = create_simulator(TEST_RUNTIME, TEST_DEVICE) |
| 12 | + |
11 | 13 | run_tests( |
12 | 14 | workspace: 'Aztec.xcworkspace', |
13 | 15 | scheme: 'Aztec', |
14 | | - devices: TEST_DEVICES, |
15 | | - deployment_target_version: IOS_VERSION, |
| 16 | + device: device.name, |
16 | 17 | prelaunch_simulator: true, |
17 | 18 | buildlog_path: File.join(__dir__, '.build', 'logs'), |
18 | | - derived_data_path: File.join(__dir__, '.build', 'derived-data') |
| 19 | + derived_data_path: File.join(__dir__, '.build', 'derived-data'), |
| 20 | + ensure_devices_found: true |
19 | 21 | ) |
| 22 | + |
| 23 | + run_tests( |
| 24 | + workspace: 'Aztec.xcworkspace', |
| 25 | + scheme: 'WordPressEditor', |
| 26 | + device: device.name, |
| 27 | + prelaunch_simulator: true, |
| 28 | + buildlog_path: File.join(__dir__, '.build', 'logs'), |
| 29 | + derived_data_path: File.join(__dir__, '.build', 'derived-data'), |
| 30 | + ensure_devices_found: true |
| 31 | + ) |
| 32 | + |
| 33 | + destroy_simulator(device) |
| 34 | + end |
| 35 | +end |
| 36 | + |
| 37 | +def create_simulator(runtime, device) |
| 38 | + fastlane_require 'simctl' |
| 39 | + fastlane_require 'securerandom' |
| 40 | + |
| 41 | + validate_runtime_exists(runtime) |
| 42 | + |
| 43 | + simulator = SimCtl.create_device( |
| 44 | + SecureRandom.uuid, |
| 45 | + SimCtl.devicetype(name: device), |
| 46 | + SimCtl.runtime(name: runtime) |
| 47 | + ) |
| 48 | + |
| 49 | + UI.success "Successfully created an #{runtime} #{device} labelled #{simulator.name}" |
| 50 | + |
| 51 | + simulator |
| 52 | +end |
| 53 | + |
| 54 | +def validate_runtime_exists(runtime) |
| 55 | + fastlane_require 'simctl' |
| 56 | + |
| 57 | + begin |
| 58 | + SimCtl.runtime({ name: runtime }) |
| 59 | + rescue StandardError |
| 60 | + SimCtl.list_runtimes.each do |existing_runtime| |
| 61 | + puts existing_runtime.name |
| 62 | + end |
| 63 | + |
| 64 | + UI.user_error! "#{runtime} is not available. Available runtimes are listed above." |
20 | 65 | end |
21 | 66 | end |
| 67 | + |
| 68 | +def destroy_simulator(simulator) |
| 69 | + runtime = simulator.runtime.name |
| 70 | + device_type_name = simulator.devicetype.name |
| 71 | + |
| 72 | + simulator.delete |
| 73 | + UI.success "Successfully deleted #{runtime} #{device_type_name}" |
| 74 | +end |
0 commit comments