Class: Fastlane::Actions::TestOptionsFromTestplanAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



89
90
91
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 89

def self.authors
  ["lyndsey-ferguson/lyndseydf"]
end

.available_optionsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 55

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :testplan,
      optional: true,
      env_name: "FL_TEST_OPTIONS_FROM_TESTPLAN_TESTPLAN",
      description: "The Xcode testplan to read the test info from",
      verify_block: proc do |test_plan|
        UI.user_error!("Error: Xcode Test Plan '#{test_plan}' is not valid!") if test_plan and test_plan.empty?
        UI.user_error!("Error: Test Plan does not exist at path '#{test_plan}'") unless File.exist?(test_plan)
      end
    )
  ]
end

.categoryObject



93
94
95
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 93

def self.category
  :testing
end

.descriptionObject



47
48
49
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 47

def self.description
  "☑️ Gets test info from a given test plan"
end

.detailsObject



51
52
53
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 51

def self.details
  "Gets tests info consisting of tests to run and whether or not code coverage is enabled"
end

.example_codeObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 74

def self.example_code
  [
    "
    UI.important(
      'example: ' \\
      'get the tests and the test coverage configuration from a given testplan'
    )
    test_options = test_options_from_testplan(
      testplan: 'AtomicBoy/AtomicBoy_2.xctestplan'
    )
    UI.message(\"The AtomicBoy_2 testplan has the following tests: \#{test_options[:only_testing]}\")
    "
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 97

def self.is_supported?(platform)
  %i[ios mac].include?(platform)
end

.return_valueObject



70
71
72
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 70

def self.return_value
  "Returns a Hash with keys :code_coverage, :only_testing, and :skip_testing for the given testplan"
end

.run(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 6

def self.run(params)
  testplan_path = params[:testplan]

  testplan = JSON.parse(File.open(testplan_path).read)
  only_testing = []
  skip_testing = []
  UI.verbose("Examining testplan JSON: #{testplan}")
  testplan['testTargets'].each do |test_target|
    testable = test_target.dig('target', 'name')
    if test_target.key?('selectedTests')
      UI.verbose("  Found selectedTests")
      test_target['selectedTests'].each do |selected_test|
        selected_test.delete!('()')
        UI.verbose("    Found test: '#{selected_test}'")
        only_testing << "#{testable}/#{selected_test.sub('\/', '/')}"
      end
    end
    if test_target.key?('skippedTests')
      UI.verbose("  Found skippedTests")
      test_target['skippedTests'].each do |skipped_test|
        skipped_test.delete!('()')
        UI.verbose("    Found test: '#{skipped_test}'")
        skip_testing << "#{testable}/#{skipped_test.sub('\/', '/')}"
      end
    end
    unless test_target.key?('selectedTests') || test_target.key?('skippedTests')
      UI.verbose("  No selected or skipped tests, using testable '#{testable}'")
      only_testing << testable
    end
  end
  {
    code_coverage: testplan.dig('defaultOptions', 'codeCoverage'),
    only_testing: only_testing,
    skip_testing: skip_testing
  }
end