|
| 1 | +module Fastlane |
| 2 | + module Actions |
| 3 | + class SimulatorWatch < FastlaneCore::Simulator |
| 4 | + class << self |
| 5 | + def requested_os_type |
| 6 | + 'watchOS' |
| 7 | + end |
| 8 | + end |
| 9 | + end |
| 10 | + |
| 11 | + _ios_sim = FastlaneCore::Simulator.all.last |
| 12 | + _tvos_sim = FastlaneCore::SimulatorTV.all.last |
| 13 | + _watchos_sim = SimulatorWatch.all.last |
| 14 | + |
| 15 | + BUILD_LOG_DIR = ENV['CIRCLE_ARTIFACTS'] || "fastlane/test_output/build_log" |
| 16 | + TEST_REPORTS_DIR = ENV['CIRCLE_TEST_REPORTS'] || "fastlane/test_output/test_report" |
| 17 | + |
| 18 | + SIMULATORS = { |
| 19 | + :OSX => "platform=OS X", |
| 20 | + :iOS => _ios_sim && "platform=iOS Simulator,name=#{_ios_sim}", |
| 21 | + :tvOS => _tvos_sim && "platform=tvOS Simulator,name=#{_tvos_sim}", |
| 22 | + :watchOS => _watchos_sim && "platform=watchOS Simulator,name=#{_watchos_sim}" |
| 23 | + } |
| 24 | + |
| 25 | + class TestUniversalFrameworkAction < Action |
| 26 | + |
| 27 | + def self._test_platform(platform, scheme: "OSX") |
| 28 | + if SIMULATORS[platform.to_sym].nil? then |
| 29 | + raise "Simulator not found for #{platform}." |
| 30 | + end |
| 31 | + |
| 32 | + require 'scan' |
| 33 | + |
| 34 | + config = FastlaneCore::Configuration.create(Scan::Options.available_options, { |
| 35 | + scheme: scheme, |
| 36 | + destination: SIMULATORS[platform], |
| 37 | + code_coverage: true, |
| 38 | + buildlog_path: "#{BUILD_LOG_DIR}/#{platform}", |
| 39 | + output_directory: "#{TEST_REPORTS_DIR}/#{platform}", |
| 40 | + clean: true |
| 41 | + }) |
| 42 | + |
| 43 | + Fastlane::Actions::ScanAction.run(config) |
| 44 | + end |
| 45 | + |
| 46 | + def self.run(params) |
| 47 | + Helper.log.info "Run TestUniversalFrameworkAction." |
| 48 | + |
| 49 | + _test_platform(params[:platform], scheme: params[:scheme]) |
| 50 | + end |
| 51 | + |
| 52 | + ##################################################### |
| 53 | + # @!group Documentation |
| 54 | + ##################################################### |
| 55 | + |
| 56 | + def self.description |
| 57 | + "Runs tests in target platform." |
| 58 | + end |
| 59 | + |
| 60 | + def self.available_options |
| 61 | + [ |
| 62 | + FastlaneCore::ConfigItem.new(key: :platform, |
| 63 | + env_name: "FL_TEST_UNIVERSAL_FRAMEWORK_PLATFORM", |
| 64 | + description: "Xcode simulator platform for testing universal framework", |
| 65 | + is_string: false, |
| 66 | + verify_block: proc do |value| |
| 67 | + raise "No platform for TestUniversalFramework given, pass using `platform: 'platform'`".red unless (value and not value.empty?) |
| 68 | + end), |
| 69 | + FastlaneCore::ConfigItem.new(key: :scheme, |
| 70 | + env_name: "FL_TEST_UNIVERSAL_FRAMEWORK_SCHEME", |
| 71 | + description: "Xcode scheme for testing universal framework", |
| 72 | + verify_block: proc do |value| |
| 73 | + raise "No scheme for TestUniversalFramework given, pass using `scheme: 'scheme'`".red unless (value and not value.empty?) |
| 74 | + end) |
| 75 | + ] |
| 76 | + end |
| 77 | + |
| 78 | + def self.authors |
| 79 | + ["Yasuhiro Inami"] |
| 80 | + end |
| 81 | + |
| 82 | + def self.is_supported?(platform) |
| 83 | + true |
| 84 | + end |
| 85 | + end |
| 86 | + end |
| 87 | +end |
0 commit comments