fastlane-plugin-xcresult_to_junit 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1148c0c7a8073cf7e839095b600304076b3347816a4ddc4d7cb2e0a7037fdc00
4
- data.tar.gz: a619ba21e9a4f6ca4d225c3c3a2da76685d40cbc1501e7b45346fca995d2652c
3
+ metadata.gz: 5fb16088624384792afda4ba43156a6485580ab8b0cd808baf10a04c42727f4a
4
+ data.tar.gz: 447f6c542dcca98230ce368e95d655e768106e7c2eeff2ed758634bed1766d24
5
5
  SHA512:
6
- metadata.gz: a4eb1e3c72642ce13efbc0fc839dec2415cfe53ff50cf2d9c058995a76f7d69378d34efdda1167aa95e0ffe203a1b4ed8a26c4b3c00de682fdddbab2e887e018
7
- data.tar.gz: e0971b4c44766e3f11bdb6301462a0e732cac9e87edd098122dc72390e6f96c575f7b9ab36c36317c15dc050013f8584959eac263b0c19fb60f7aac2aec61584
6
+ metadata.gz: a9ec29588cd4dac9e632675739885695da3b4d010a78c444212383d77dafd622e99a07dc98e954745a007c1310c6d4b0ae778761bb65867a6149cd0abd9526f0
7
+ data.tar.gz: 7e181a71f6b9a3a331c8b1a969c0b26e28354f5ada6630e4a8d3aa08b8242d53c492d6b68a5573dd6261a0b2e6942a1d51cacac33b8a4149b13e23d3a8a3f656
@@ -9,78 +9,107 @@ module Fastlane
9
9
  UI.message("The xcresult_to_junit plugin has started!")
10
10
  all_results = Helper::XcresultToJunitHelper.load_results(params[:xcresult_path])['actions']['_values']
11
11
  all_results.each do |test_run|
12
- if test_run['actionResult']['testsRef'] # Skip if section has no testRef data as this means its not a test run
13
- map = {}
14
- junit_folder = Helper::XcresultToJunitHelper.save_device_details_to_file(params[:output_path], test_run['runDestination'])
15
- test_run_id = test_run['actionResult']['testsRef']['id']['_value']
16
- all_tests = Helper::XcresultToJunitHelper.load_object(params[:xcresult_path], test_run_id)['summaries']['_values'][0]['testableSummaries']['_values']
17
- test_suites = []
18
- all_tests.each do |target|
19
- target_name = target['targetName']['_value']
20
- unless target['tests']
21
- failure_summary = target['failureSummaries']['_values'][0]
22
- test_suites << { name: target_name, error: failure_summary['message']['_value'] }
23
- next
24
- end
25
- test_classes = []
26
- if defined?(target['tests']['_values'][0]['subtests']['_values'][0]['subtests']['_values'])
27
- test_classes = target['tests']['_values'][0]['subtests']['_values'][0]['subtests']['_values']
28
- end
29
- test_classes.each do |test_class|
30
- suite_name = "#{target_name}.#{test_class['name']['_value']}"
31
- suite = { name: suite_name, cases: [] }
32
- if test_class['subtests']
33
- test_class['subtests']['_values'].each do |test|
34
- duration = 0
35
- duration = test['duration']['_value'] if test['duration']
36
- testcase_name = test['name']['_value'].tr('()', '')
37
- tags = testcase_name.split('_')[1..-1]
38
- testcase_name = testcase_name.split('_').first
39
- testcase = { name: testcase_name, time: duration }
40
- map["#{suite_name}.#{testcase_name}"] = {'files' => [], 'tags' => tags}
12
+ next unless test_run['actionResult']['testsRef'] # Skip if section has no testRef data as this means its not a test run
13
+ map = {}
14
+ junit_folder = Helper::XcresultToJunitHelper.save_device_details_to_file(params[:output_path], test_run['runDestination'])
15
+ test_run_id = test_run['actionResult']['testsRef']['id']['_value']
16
+ all_tests = Helper::XcresultToJunitHelper.load_object(params[:xcresult_path], test_run_id)['summaries']['_values'][0]['testableSummaries']['_values']
17
+ test_suites = []
18
+ all_tests.each do |target|
19
+ target_name = target['targetName']['_value']
20
+ unless target['tests']
21
+ failure_summary = target['failureSummaries']['_values'][0]
22
+ test_suites << { name: target_name, error: failure_summary['message']['_value'] }
23
+ next
24
+ end
25
+ test_classes = []
26
+ if defined?(target['tests']['_values'][0]['subtests']['_values'][0]['subtests']['_values'])
27
+ test_classes = target['tests']['_values'][0]['subtests']['_values'][0]['subtests']['_values']
28
+ end
29
+ test_classes.each do |test_class|
30
+ suite_name = "#{target_name}.#{test_class['name']['_value']}"
31
+ suite = { name: suite_name, cases: [] }
32
+ if test_class['subtests']
33
+ test_class['subtests']['_values'].each do |test|
34
+ duration = 0
35
+ duration = test['duration']['_value'] if test['duration']
36
+ testcase_name = test['name']['_value'].tr('()', '')
37
+ tags = testcase_name.split('_')[1..-1]
38
+ testcase_name = testcase_name.split('_').first
39
+ testcase = { name: testcase_name, time: duration }
40
+ map["#{suite_name}.#{testcase_name}"] = { 'files' => [], 'tags' => tags }
41
41
 
42
- if defined?(test['summaryRef']['id']['_value'])
43
- summaryRef = test['summaryRef']['id']['_value']
44
- ref = Helper::XcresultToJunitHelper.load_object(params[:xcresult_path], summaryRef)
45
- if defined?(ref['activitySummaries']['_values'])
46
- ref['activitySummaries']['_values'].each do |summary|
47
- if summary['attachments']
48
- summary['attachments']['_values'].each do |attachment|
49
- timestamp = DateTime.parse(attachment['timestamp']['_value']).to_time.to_i
50
- name = attachment['name']['_value']
51
- folder_name = "#{suite_name}.#{testcase_name}"
52
- id = attachment['payloadRef']['id']['_value']
53
- Helper::XcresultToJunitHelper.fetch_screenshot(params[:xcresult_path], "#{junit_folder}/attachments/#{folder_name}", "#{id}.png", id)
54
- map[folder_name]['files'].push({'description' => name, 'mime-type' => 'image/png', 'path' => "#{folder_name}/#{id}.png", 'timestamp' => timestamp})
55
- end
56
- end
42
+ if defined?(test['summaryRef']['id']['_value'])
43
+ summary_ref = test['summaryRef']['id']['_value']
44
+ ref = Helper::XcresultToJunitHelper.load_object(params[:xcresult_path], summary_ref)
45
+ if defined?(ref['activitySummaries']['_values'])
46
+ ref['activitySummaries']['_values'].each do |summary|
47
+ next unless summary['attachments']
48
+ summary['attachments']['_values'].each do |attachment|
49
+ name = attachment['name']['_value']
50
+ next unless name != 'kXCTAttachmentLegacyDiagnosticReportData'
51
+ timestamp = DateTime.parse(attachment['timestamp']['_value']).to_time.to_i
52
+ filename = attachment['filename']['_value']
53
+ folder_name = "#{suite_name}.#{testcase_name}"
54
+ id = attachment.dig('payloadRef', 'id', '_value')
55
+ next if id.nil?
56
+ Helper::XcresultToJunitHelper.fetch_screenshot(params[:xcresult_path], "#{junit_folder}/attachments/#{folder_name}", filename.to_s, id)
57
+ map[folder_name]['files'].push({ 'description' => name, 'mime-type' => 'image/png', 'path' => "#{folder_name}/#{filename}", 'timestamp' => timestamp })
57
58
  end
58
59
  end
59
60
  end
60
61
 
61
- if test['testStatus']['_value'] == 'Failure'
62
- failure = Helper::XcresultToJunitHelper.load_object(params[:xcresult_path], test['summaryRef']['id']['_value'])['failureSummaries']['_values'][0]
63
- filename = failure['fileName']['_value']
64
- message = failure['message']['_value']
65
- if filename == '<unknown>'
66
- testcase[:error] = message
67
- else
68
- testcase[:failure] = message
69
- testcase[:failure_location] = "#{filename}:#{failure['lineNumber']['_value']}"
62
+ if defined?(ref['performanceMetrics']['_value'])
63
+ performancemetrics = ""
64
+ ref['performanceMetrics']['_values'].each do |metric|
65
+ metricname = metric['displayName']['_value']
66
+ if defined?(metric['baselineAverage']['_value'])
67
+ metricbaseline = metric['baselineAverage']['_value']
68
+ else
69
+ metricbaseline = 0
70
+ end
71
+ metricmaxdev = metric['maxPercentRelativeStandardDeviation']['_value']
72
+ metricunit = metric['unitOfMeasurement']['_value']
73
+ metricave = 0
74
+ measurecount = 0
75
+ metric['measurements']['_values'].each do |measure|
76
+ metricave += measure['_value'].to_f
77
+ measurecount += 1
78
+ end
79
+ metricave = (metricave / measurecount).round(2)
80
+ if metricbaseline != 0
81
+ metricresult = (((metricbaseline.to_f - metricave) / metricbaseline.to_f) * 100).round(2)
82
+ else
83
+ metricresult = 0
84
+ end
85
+ performancemetric = "\nMetric: #{metricname}\nResult: #{metricresult}%\nAverage: #{metricave}#{metricunit}\nBaseline: #{metricbaseline}#{metricunit}\nMax Deviation: #{metricmaxdev}%\n\n"
86
+ performancemetrics << performancemetric
70
87
  end
88
+ testcase[:performance] = performancemetrics
71
89
  end
72
- suite[:cases] << testcase
73
90
  end
91
+ if test['testStatus']['_value'] == 'Failure'
92
+ failure = Helper::XcresultToJunitHelper.load_object(params[:xcresult_path], test['summaryRef']['id']['_value'])['failureSummaries']['_values'][0]
93
+ filename = failure.dig('fileName', '_value')
94
+ message = failure['message']['_value']
95
+ if filename == '<unknown>' || filename.nil?
96
+ testcase[:error] = message
97
+ else
98
+ testcase[:failure] = message
99
+ testcase[:failure_location] = "#{filename}:#{failure['lineNumber']['_value']}"
100
+ end
101
+ end
102
+ suite[:cases] << testcase
74
103
  end
75
- suite[:count] = suite[:cases].size
76
- suite[:failures] = suite[:cases].count { |testcase| testcase[:failure] }
77
- suite[:errors] = suite[:cases].count { |testcase| testcase[:error] }
78
- test_suites << suite
79
104
  end
105
+ suite[:count] = suite[:cases].size
106
+ suite[:failures] = suite[:cases].count { |testcase| testcase[:failure] }
107
+ suite[:errors] = suite[:cases].count { |testcase| testcase[:error] }
108
+ test_suites << suite
80
109
  end
81
- Helper::XcresultToJunitHelper.generate_junit(junit_folder, test_suites)
82
- Helper::XcresultToJunitHelper.save_screenshot_mapping(map, "#{junit_folder}/attachments/")
83
110
  end
111
+ Helper::XcresultToJunitHelper.generate_junit(junit_folder, test_suites)
112
+ Helper::XcresultToJunitHelper.save_screenshot_mapping(map, "#{junit_folder}/attachments/")
84
113
  end
85
114
  UI.message("The xcresult_to_junit plugin has finished!")
86
115
  end
@@ -108,17 +137,17 @@ module Fastlane
108
137
  description: "The path to the xcresult file",
109
138
  optional: false,
110
139
  type: String),
111
- FastlaneCore::ConfigItem.new(key: :output_path,
112
- env_name: "XCRESULT_TO_JUNIT_OUTPUT_PATH",
113
- description: "The path where the output will be placed",
114
- optional: false,
115
- type: String)
116
- ]
117
- end
118
-
119
- def self.is_supported?(platform)
120
- [:ios, :mac].include?(platform)
121
- end
122
- end
140
+ FastlaneCore::ConfigItem.new(key: :output_path,
141
+ env_name: "XCRESULT_TO_JUNIT_OUTPUT_PATH",
142
+ description: "The path where the output will be placed",
143
+ optional: false,
144
+ type: String)
145
+ ]
146
+ end
147
+
148
+ def self.is_supported?(platform)
149
+ [:ios, :mac].include?(platform)
123
150
  end
124
151
  end
152
+ end
153
+ end
@@ -8,18 +8,18 @@ module Fastlane
8
8
  module Helper
9
9
  class XcresultToJunitHelper
10
10
  def self.load_object(xcresult_path, id)
11
- JSON.load FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get --format json --path #{xcresult_path} --id #{id}")
11
+ JSON.parse(FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get --format json --path #{xcresult_path} --id #{id}"))
12
12
  end
13
13
 
14
14
  def self.load_results(xcresult_path)
15
- JSON.load FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get --format json --path #{xcresult_path}")
15
+ JSON.parse(FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get --format json --path #{xcresult_path}"))
16
16
  end
17
17
 
18
18
  def self.fetch_screenshot(xcresult_path, output_path, file_name, id)
19
- if !File.directory?(output_path)
20
- FileUtils.mkdir output_path
19
+ unless File.directory?(output_path)
20
+ FileUtils.mkdir(output_path)
21
21
  end
22
- JSON.load FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool export --path #{xcresult_path} --output-path #{output_path}/#{file_name} --id #{id} --type file")
22
+ FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool export --path #{xcresult_path} --output-path \"#{output_path}/#{file_name}\" --id #{id} --type file")
23
23
  end
24
24
 
25
25
  def self.save_screenshot_mapping(map_hash, output_path)
@@ -37,9 +37,8 @@ module Fastlane
37
37
  }.to_json
38
38
 
39
39
  junit_folder = "#{output_path}/ios-#{device_udid}.junit"
40
- FileUtils.rm_rf junit_folder
41
- FileUtils.mkdir junit_folder
42
- FileUtils.mkdir "#{junit_folder}/attachments"
40
+ FileUtils.rm_rf(junit_folder)
41
+ FileUtils.mkdir_p("#{junit_folder}/attachments")
43
42
  File.open("#{junit_folder}/device.json", 'w') do |f|
44
43
  f << device_details
45
44
  end
@@ -47,52 +46,52 @@ module Fastlane
47
46
  end
48
47
 
49
48
  def self.junit_file_start
50
- puts '<?xml version="1.0" encoding="UTF-8"?>'
51
- puts '<testsuites>'
49
+ puts('<?xml version="1.0" encoding="UTF-8"?>')
50
+ puts('<testsuites>')
52
51
  end
53
52
 
54
53
  def self.junit_file_end
55
- puts '</testsuites>'
54
+ puts('</testsuites>')
56
55
  end
57
56
 
58
57
  def self.junit_suite_error(suite)
59
- puts "<testsuite name=#{suite[:name].encode xml: :attr} errors='1'>"
60
- puts "<error>#{suite[:error].encode xml: :text}</error>"
58
+ puts("<testsuite name=#{suite[:name].encode(xml: :attr)} errors='1'>")
59
+ puts("<error>#{suite[:error].encode(xml: :text)}</error>")
61
60
  end
62
61
 
63
62
  def self.junit_suite_start(suite)
64
- puts "<testsuite name=#{suite[:name].encode xml: :attr} tests='#{suite[:count]}' failures='#{suite[:failures]}' errors='#{suite[:errors]}'>"
63
+ puts("<testsuite name=#{suite[:name].encode(xml: :attr)} tests='#{suite[:count]}' failures='#{suite[:failures]}' errors='#{suite[:errors]}'>")
65
64
  end
66
65
 
67
66
  def self.junit_suite_end
68
- puts '</testsuite>'
67
+ puts('</testsuite>')
69
68
  end
70
69
 
71
70
  def self.junit_testcase_start(suite, testcase)
72
- print "<testcase name=#{testcase[:name].encode xml: :attr} classname=#{suite[:name].encode xml: :attr} time='#{testcase[:time]}'"
71
+ print("<testcase name=#{testcase[:name].encode(xml: :attr)} classname=#{suite[:name].encode(xml: :attr)} time='#{testcase[:time]}'>")
73
72
  end
74
73
 
75
- def self.junit_testcase_success
76
- puts '/>'
74
+ def self.junit_testcase_end
75
+ puts('</testcase>')
77
76
  end
78
77
 
79
78
  def self.junit_testcase_failure(testcase)
80
- puts '>'
81
- puts "<failure message=#{testcase[:failure].encode xml: :attr}>#{testcase[:failure_location].encode xml: :text}</failure>"
82
- puts '</testcase>'
79
+ puts("<failure message=#{testcase[:failure].encode(xml: :attr)}>#{testcase[:failure_location].encode(xml: :text)}</failure>")
83
80
  end
84
81
 
85
82
  def self.junit_testcase_error(testcase)
86
- puts '>'
87
- puts "<error>#{testcase[:error].encode xml: :text}</error>"
88
- puts '</testcase>'
83
+ puts("<error>#{testcase[:error].encode(xml: :text)}</error>")
84
+ end
85
+
86
+ def self.junit_testcase_performance(testcase)
87
+ puts("<system-out>#{testcase[:performance]}</system-out>")
89
88
  end
90
89
 
91
90
  def self.generate_junit(junit_folder, test_suites)
92
91
  File.open("#{junit_folder}/results.xml", 'w') do |fo|
93
92
  old_stdout = $stdout
94
93
  $stdout = fo
95
- Helper::XcresultToJunitHelper.junit_file_start()
94
+ Helper::XcresultToJunitHelper.junit_file_start
96
95
  test_suites.each do |suite|
97
96
  if suite[:error]
98
97
  Helper::XcresultToJunitHelper.junit_suite_error(suite)
@@ -104,14 +103,16 @@ module Fastlane
104
103
  Helper::XcresultToJunitHelper.junit_testcase_failure(testcase)
105
104
  elsif testcase[:error]
106
105
  Helper::XcresultToJunitHelper.junit_testcase_error(testcase)
107
- else
108
- Helper::XcresultToJunitHelper.junit_testcase_success()
109
106
  end
107
+ if testcase[:performance]
108
+ Helper::XcresultToJunitHelper.junit_testcase_performance(testcase)
109
+ end
110
+ Helper::XcresultToJunitHelper.junit_testcase_end
110
111
  end
111
112
  end
112
- Helper::XcresultToJunitHelper.junit_suite_end()
113
+ Helper::XcresultToJunitHelper.junit_suite_end
113
114
  end
114
- Helper::XcresultToJunitHelper.junit_file_end()
115
+ Helper::XcresultToJunitHelper.junit_file_end
115
116
  $stdout = old_stdout
116
117
  end
117
118
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module XcresultToJunit
3
- VERSION = "0.2.3"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-xcresult_to_junit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Birdsall
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: 2.134.0
139
- description:
139
+ description:
140
140
  email: shane.birdsall@fiserv.com
141
141
  executables: []
142
142
  extensions: []
@@ -152,7 +152,7 @@ homepage: https://github.com/zanizrules/fastlane-plugin-xcresult_to_junit
152
152
  licenses:
153
153
  - MIT
154
154
  metadata: {}
155
- post_install_message:
155
+ post_install_message:
156
156
  rdoc_options: []
157
157
  require_paths:
158
158
  - lib
@@ -167,9 +167,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubyforge_project:
170
+ rubyforge_project:
171
171
  rubygems_version: 2.7.6.2
172
- signing_key:
172
+ signing_key:
173
173
  specification_version: 4
174
174
  summary: Produces junit xml files from Xcode 11+ xcresult files
175
175
  test_files: []