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



78
79
80
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 78

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

.available_optionsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 44

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



82
83
84
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 82

def self.category
  :testing
end

.descriptionObject



36
37
38
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 36

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

.detailsObject



40
41
42
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 40

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

.example_codeObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 63

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)


86
87
88
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 86

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

.return_valueObject



59
60
61
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 59

def self.return_value
  "Returns a Hash with keys :code_coverage and :only_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
# File 'lib/fastlane/plugin/test_center/actions/test_options_from_testplan.rb', line 6

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

  testplan = JSON.load(File.open(testplan_path))
  only_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_identifiers = test_target['selectedTests'].each do |selected_test|
        selected_test.delete!('()')
        UI.verbose("    Found test: '#{selected_test}'")
        only_testing << "#{testable}/#{selected_test.sub('\/', '/')}"
      end
    else
      UI.verbose("  No selected tests, using testable '#{testable}'")
      only_testing << testable
    end
  end
  {
    code_coverage: testplan.dig('defaultOptions', 'codeCoverage'),
    only_testing: only_testing
  }
end