|
84 | 84 | # Test |
85 | 85 | ########################################## |
86 | 86 |
|
| 87 | +# Simulator device names change with every Xcode release, so pick an available |
| 88 | +# device at runtime (newest runtime first) instead of hardcoding names that rot. |
| 89 | +# Mirrors the device resolution in .github/workflows/main.yml. |
| 90 | +def available_simulator(runtime_pattern, device_prefix) |
| 91 | + require "json" |
| 92 | + devices = JSON.parse(sh("xcrun", "simctl", "list", "devices", "available", "-j", log: false))["devices"] |
| 93 | + runtimes = devices.keys.grep(runtime_pattern).sort_by { |key| key.scan(/\d+/).map(&:to_i) }.reverse |
| 94 | + runtimes.each do |runtime| |
| 95 | + device = devices[runtime].find { |d| d["name"].start_with?(device_prefix) } |
| 96 | + return device["name"] if device |
| 97 | + end |
| 98 | + nil |
| 99 | +end |
| 100 | + |
87 | 101 | desc "Run all tests" |
88 | 102 | lane :tests do |
89 | 103 | xcclean |
90 | 104 |
|
91 | | - desc "Run macOS Tests" |
92 | | - run_tests( |
93 | | - destination: "platform=macOS", |
94 | | - scheme: scheme, |
95 | | - force_quit_simulator: true, |
96 | | - reset_simulator: true, |
97 | | - prelaunch_simulator: false, |
98 | | - code_coverage: true, |
99 | | - open_report: false, |
100 | | - output_files: "report-macos.html,report-macos.junit" |
101 | | - ) |
102 | | - slather( |
103 | | - scheme: scheme, |
104 | | - proj: xcodeproj_file, |
105 | | - output_directory: "./fastlane/reports/macOS", |
106 | | - html: true, |
107 | | - show: false |
108 | | - ) |
109 | | - |
110 | | - desc "Run iOS Tests" |
111 | | - run_tests( |
112 | | - destination: "platform=iOS Simulator,name=iPhone 15 Pro", |
113 | | - scheme: scheme, |
114 | | - force_quit_simulator: true, |
115 | | - reset_simulator: true, |
116 | | - prelaunch_simulator: false, |
117 | | - code_coverage: true, |
118 | | - open_report: false, |
119 | | - output_files: "report-ios.html,report-ios.junit" |
120 | | - ) |
121 | | - slather( |
122 | | - scheme: scheme, |
123 | | - proj: xcodeproj_file, |
124 | | - output_directory: "./fastlane/reports/iOS", |
125 | | - html: true, |
126 | | - show: false |
127 | | - ) |
128 | | - |
129 | | - desc "Run tvOS Tests" |
130 | | - run_tests( |
131 | | - destination: "platform=tvOS Simulator,name=Apple TV 4K (3rd generation)", |
132 | | - scheme: scheme, |
133 | | - force_quit_simulator: true, |
134 | | - reset_simulator: true, |
135 | | - prelaunch_simulator: false, |
136 | | - code_coverage: true, |
137 | | - open_report: false, |
138 | | - output_files: "report-tvos.html,report-tvos.junit" |
139 | | - ) |
140 | | - slather( |
141 | | - scheme: scheme, |
142 | | - proj: xcodeproj_file, |
143 | | - output_directory: "./fastlane/reports/tvOS", |
144 | | - html: true, |
145 | | - show: false |
146 | | - ) |
147 | | - |
148 | | - desc "Run watchOS Tests" |
149 | | - run_tests( |
150 | | - destination: "platform=watchOS Simulator,name=Apple Watch Series 9 (45mm)", |
151 | | - scheme: scheme, |
152 | | - force_quit_simulator: true, |
153 | | - reset_simulator: true, |
154 | | - prelaunch_simulator: false, |
155 | | - code_coverage: true, |
156 | | - open_report: false, |
157 | | - output_files: "report-watchos.html,report-watchos.junit" |
158 | | - ) |
159 | | - slather( |
160 | | - scheme: scheme, |
161 | | - proj: xcodeproj_file, |
162 | | - output_directory: "./fastlane/reports/watchOS", |
163 | | - html: true, |
164 | | - show: false |
165 | | - ) |
| 105 | + targets = [ |
| 106 | + { name: "macOS", destination: "platform=macOS" }, |
| 107 | + { name: "iOS", platform: "iOS", runtime: /SimRuntime\.iOS-/, prefix: "iPhone" }, |
| 108 | + { name: "tvOS", platform: "tvOS", runtime: /SimRuntime\.tvOS-/, prefix: "Apple TV" }, |
| 109 | + { name: "watchOS", platform: "watchOS", runtime: /SimRuntime\.watchOS-/, prefix: "Apple Watch" }, |
| 110 | + { name: "visionOS", platform: "visionOS", runtime: /SimRuntime\.(xrOS|visionOS)-/, prefix: "Apple Vision" }, |
| 111 | + ] |
| 112 | + skipped = [] |
| 113 | + |
| 114 | + targets.each do |target| |
| 115 | + destination = target[:destination] |
| 116 | + if destination.nil? then |
| 117 | + device = available_simulator(target[:runtime], target[:prefix]) |
| 118 | + if device.nil? then |
| 119 | + UI.important("Skipping #{target[:name]} tests: no available #{target[:prefix]} simulator. Install the runtime from Xcode > Settings > Components.") |
| 120 | + skipped << target[:name] |
| 121 | + next |
| 122 | + end |
| 123 | + destination = "platform=#{target[:platform]} Simulator,name=#{device}" |
| 124 | + end |
166 | 125 |
|
167 | | - desc "Run visionOS Tests" |
168 | | - run_tests( |
169 | | - destination: "platform=visionOS Simulator,name=Apple Vision Pro", |
170 | | - scheme: scheme, |
171 | | - force_quit_simulator: true, |
172 | | - reset_simulator: true, |
173 | | - prelaunch_simulator: false, |
174 | | - code_coverage: true, |
175 | | - open_report: false, |
176 | | - output_files: "report-visionos.html,report-visionos.junit" |
177 | | - ) |
178 | | - slather( |
179 | | - scheme: scheme, |
180 | | - proj: xcodeproj_file, |
181 | | - output_directory: "./fastlane/reports/visionOS", |
182 | | - html: true, |
183 | | - show: false |
184 | | - ) |
| 126 | + UI.header("Run #{target[:name]} Tests (#{destination})") |
| 127 | + report = target[:name].downcase |
| 128 | + run_tests( |
| 129 | + destination: destination, |
| 130 | + scheme: scheme, |
| 131 | + force_quit_simulator: true, |
| 132 | + reset_simulator: true, |
| 133 | + prelaunch_simulator: false, |
| 134 | + code_coverage: true, |
| 135 | + open_report: false, |
| 136 | + output_files: "report-#{report}.html,report-#{report}.junit" |
| 137 | + ) |
| 138 | + slather( |
| 139 | + scheme: scheme, |
| 140 | + proj: xcodeproj_file, |
| 141 | + output_directory: "./fastlane/reports/#{target[:name]}", |
| 142 | + html: true, |
| 143 | + show: false |
| 144 | + ) |
| 145 | + end |
185 | 146 |
|
| 147 | + UI.important("Skipped platforms: #{skipped.join(", ")}") unless skipped.empty? |
186 | 148 | end |
187 | 149 |
|
188 | 150 | ########################################## |
|
0 commit comments