Class: Fastlane::Actions::SuppressTestsFromJunitAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



128
129
130
# File 'lib/fastlane/plugin/test_center/actions/suppress_tests_from_junit.rb', line 128

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

.available_optionsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fastlane/plugin/test_center/actions/suppress_tests_from_junit.rb', line 54

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :xcodeproj,
      env_name: "FL_SUPPRESS_TESTS_FROM_JUNIT_XCODE_PROJECT",
      description: "The file path to the Xcode project file to modify",
      verify_block: proc do |path|
        UI.user_error!("Error: Xcode project file path not given!") unless path and !path.empty?
        UI.user_error!("Error: Xcode project '#{path}' not found!") unless Dir.exist?(path)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :junit,
      env_name: "FL_SUPPRESS_TESTS_FROM_JUNIT_JUNIT_REPORT",
      description: "The junit xml report file from which to collect the tests to suppress",
      verify_block: proc do |path|
        UI.user_error!("Error: cannot find the junit xml report file '#{path}'") unless File.exist?(path)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :scheme,
      optional: true,
      env_name: "FL_SUPPRESS_TESTS_FROM_JUNIT_SCHEME_TO_UPDATE",
      description: "The Xcode scheme where the tests should be suppressed",
      verify_block: proc do |scheme_name|
        UI.user_error!("Error: Xcode Scheme '#{scheme_name}' is not valid!") if scheme_name and scheme_name.empty?
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :suppress_type,
      type: Symbol,
      env_name: "FL_SUPPRESS_TESTS_FROM_JUNIT_SUPPRESS_TYPE",
      description: "Tests to suppress are either :failed or :passing",
      verify_block: proc do |type|
        UI.user_error!("Error: suppress type ':#{type}' is invalid! Only :failed or :passing are valid types") unless %i[failed passing].include?(type)
      end
    )
  ]
end

.categoryObject



132
133
134
# File 'lib/fastlane/plugin/test_center/actions/suppress_tests_from_junit.rb', line 132

def self.category
  :testing
end

.descriptionObject

:nocov:



50
51
52
# File 'lib/fastlane/plugin/test_center/actions/suppress_tests_from_junit.rb', line 50

def self.description
  "🗜 Uses a junit xml report file to suppress either passing or failing tests in an Xcode Scheme"
end

.example_codeObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fastlane/plugin/test_center/actions/suppress_tests_from_junit.rb', line 94

def self.example_code
  [
    "
    UI.important(
      'example: ' \\
      'suppress the tests that failed in the junit report for _all_ Schemes'
    )
    suppress_tests_from_junit(
      xcodeproj: 'AtomicBoy/AtomicBoy.xcodeproj',
      junit: './spec/fixtures/junit.xml',
      suppress_type: :failed
    )
    UI.message(
      \"Suppressed tests for project: \#{suppressed_tests(xcodeproj: 'AtomicBoy/AtomicBoy.xcodeproj')}\"
    )
    ",
    "
    UI.important(
      'example: ' \\
      'suppress the tests that failed in the junit report for _one_ Scheme'
    )
    suppress_tests_from_junit(
      xcodeproj: 'AtomicBoy/AtomicBoy.xcodeproj',
      junit: './spec/fixtures/junit.xml',
      scheme: 'Professor',
      suppress_type: :failed
    )
    UI.message(
      \"Suppressed tests for the 'Professor' scheme: \#{suppressed_tests(xcodeproj: 'AtomicBoy/AtomicBoy.xcodeproj')}\"
    )
    "
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/fastlane/plugin/test_center/actions/suppress_tests_from_junit.rb', line 136

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

.run(params) ⇒ Object



4
5
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
42
43
# File 'lib/fastlane/plugin/test_center/actions/suppress_tests_from_junit.rb', line 4

def self.run(params)
  project_path = params[:xcodeproj]
  scheme = params[:scheme]

  scheme_filepaths = Dir.glob("#{project_path}/{xcshareddata,xcuserdata}/**/xcschemes/#{scheme || '*'}.xcscheme")
  if scheme_filepaths.length.zero?
    UI.user_error!("Error: cannot find any scheme named #{scheme}") unless scheme.nil?
    UI.user_error!("Error: cannot find any schemes in the Xcode project")
  end

  testables = Hash.new([])
  desired_passed_status = (params[:suppress_type] == :passing)

  report = ::TestCenter::Helper::XcodeJunit::Report.new(params[:junit])

  report.testables.each do |testable|
    testables[testable.name] = []
    testable.testsuites.each do |testsuite|
      testsuite.testcases.each do |testcase|
        if testcase.passed? == desired_passed_status
          testables[testable.name] << testcase.skipped_test
        end
      end
    end
  end

  scheme_filepaths.each do |scheme_filepath|
    is_dirty = false
    xcscheme = Xcodeproj::XCScheme.new(scheme_filepath)

    xcscheme.test_action.testables.each do |testable|
      buildable_name = testable.buildable_references[0].buildable_name
      testables[buildable_name].each do |skipped_test|
        testable.add_skipped_test(skipped_test)
        is_dirty = true
      end
    end
    xcscheme.save! if is_dirty
  end
end