class Fastlane::Actions::SuppressTestsFromJunitAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/suppress_tests_from_junit.rb, line 93
def self.authors
  ["lyndsey-ferguson/@lyndseydf"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/suppress_tests_from_junit.rb, line 53
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
description() click to toggle source

@!group Documentation

# File lib/fastlane/plugin/retry_tests/actions/suppress_tests_from_junit.rb, line 49
def self.description
  "Uses a junit xml report file to suppress either passing or failing tests in an Xcode Scheme"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/suppress_tests_from_junit.rb, line 97
def self.is_supported?(platform)
  platform == :ios
end
run(params) click to toggle source
# File lib/fastlane/plugin/retry_tests/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