Skip to content

Commit 5c49bf7

Browse files
committed
add XCResult::ExportOptions
1 parent 540384e commit 5c49bf7

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

lib/xcresult/export_options.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module XCResult
2+
class ExportOptions
3+
AVAILABLE_OPTIONS = %i[destination by_device by_locale].freeze
4+
5+
def initialize(**options)
6+
raise ':destination option is required' unless options[:destination]
7+
8+
options.each do |key, value|
9+
raise "Found unknown option #{key} - #{value}." unless AVAILABLE_OPTIONS.include?(key)
10+
end
11+
12+
@options = options.dup
13+
@destination = options.delete(:destination)
14+
end
15+
16+
def output_directory(target_device_record:, action_testable_summary:)
17+
output_directory = @destination
18+
19+
# keep the order of given options so that you can customize output directory path based on your needs
20+
@options.each do |key, value|
21+
if key == :by_device && value == true
22+
output_directory = File.join(output_directory, target_device_record.model_name)
23+
elsif key == :by_locale && value == true
24+
locale = [action_testable_summary.test_language, action_testable_summary.test_region].compact.join('_')
25+
locale = 'UNKOWN' if locale.empty?
26+
output_directory = File.join(output_directory, locale)
27+
end
28+
end
29+
30+
output_directory
31+
end
32+
end
33+
end

lib/xcresult/parser.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
require 'json'
55
require 'fileutils'
66

7+
require_relative 'export_options'
8+
79
module XCResult
810
class Parser
911
attr_accessor :path, :result_bundle_json, :actions_invocation_record
@@ -69,7 +71,7 @@ def export_xccovarchives(destination: nil)
6971
end
7072
end
7173

72-
def export_screenshots(destination: Dir.pwd, by_device: false, by_locale: false)
74+
def export_screenshots(options = XCResult::ExportOptions.new(destination: Dir.pwd))
7375
# Filter non test results; i.e build action
7476
actions = actions_invocation_record.actions.select {|x| x.action_result.tests_ref }
7577

@@ -89,11 +91,10 @@ def export_screenshots(destination: Dir.pwd, by_device: false, by_locale: false)
8991
.flat_map(&:attachments)
9092

9193
# Prepare output directory for each tests
92-
locale = [action_testable_summary.test_language, action_testable_summary.test_region].compact.join('_')
93-
locale = 'UNKOWN' if locale.empty?
94-
output_directory = destination
95-
output_directory = File.join(output_directory, action.run_destination.target_device_record.model_name) if by_device
96-
output_directory = File.join(output_directory, locale) if by_locale
94+
output_directory = options.output_directory(
95+
target_device_record: action.run_destination.target_device_record,
96+
action_testable_summary: action_testable_summary
97+
)
9798
FileUtils.mkdir_p(output_directory) unless Dir.exist?(output_directory)
9899

99100
# Finally exports attachments

0 commit comments

Comments
 (0)