fastlane-plugin-xcresult_to_junit_fork 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87712d914f0288a505e7e088508dddb0dd8fa3a7353673c0e18a647709f44587
4
+ data.tar.gz: c8d64c5c6055df94bac0cb57d71dbe619a160457d1e5ee55e626e2ede112c785
5
+ SHA512:
6
+ metadata.gz: dc22eafeef1ce220a5a6fd389d5d5e9a09170dd28d17225737934b3d74d438a1cde5c0074d549428a1bba73177720f8abc4e3fe322e65ea0d8b85fb3137a0e9f
7
+ data.tar.gz: db65c89d49cf4431cdcce3a89c29ca68744c270e7b23de8676a573d3b9d338c3d1a3130a5bf7c1f618e3a490116a925dd24e21ab95fe44347cdb4a4816547ffb
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Shane Birdsall <shane.birdsall@fiserv.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # xcresult_to_junit plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-xcresult_to_junit)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-xcresult_to_junit`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin xcresult_to_junit
11
+ ```
12
+
13
+ ## About xcresult_to_junit
14
+
15
+ This plugin produces junit xml files from Xcode 11+ xcresult files.
16
+
17
+ This tool is not designed to work with result files produced with xcode versions older than xcode 11.
18
+
19
+ My main motivation behind creating my own solution was to have a plugin that works in a variety of testing scenarios.
20
+ The below table captures the current requirements this plugin meets. If you have a requirement that is not met by this plugin and would like to contribute then please feel free :metal:
21
+
22
+ | Requirement | Status |
23
+ |---------------------------------------|--------------------|
24
+ | Works against one iOS device | :white_check_mark: |
25
+ | Works against multiple iOS device | :white_check_mark: |
26
+ | Generates one junit report per target | :white_check_mark: |
27
+ | Works with modern formats (Xcode 11+) | :white_check_mark: |
28
+
29
+ ## Example
30
+
31
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
32
+
33
+ Ensure you specify the following when you call scan
34
+
35
+ ```ruby
36
+ fail_build: false, # Allows to continue after scan
37
+ result_bundle: true # Generate xcresult in output directory
38
+ ```
39
+
40
+ After scan you can call the plugin, which will look something like this
41
+
42
+ ```ruby
43
+ xcresult_to_junit(xcresult_path: './fastlane/test_output/MyScheme.test_result.xcresult', output_path: './fastlane/test_output/')
44
+ ```
45
+
46
+ We can get a list of the junit reports generated by doing something like so
47
+
48
+ ```ruby
49
+ junit_reports = Dir['./test_output/*.junit']
50
+ # Now we can iterate over the reports and send them where they need to go
51
+ # My test_output folder would ideally have been cleaned before this test run to avoid old results
52
+ ```
53
+
54
+ ## Run tests for this plugin
55
+
56
+ To run both the tests, and code style validation, run
57
+
58
+ ```bash
59
+ rake
60
+ ```
61
+
62
+ To automatically fix many of the styling issues, use
63
+
64
+ ```bash
65
+ rubocop -A
66
+ ```
67
+
68
+ ## Issues and Feedback
69
+
70
+ For any other issues and feedback about this plugin, please submit it to this repository.
71
+
72
+ ## Troubleshooting
73
+
74
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
75
+
76
+ ## Using _fastlane_ Plugins
77
+
78
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
79
+
80
+ ## About _fastlane_
81
+
82
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fastlane/plugin/xcresult_to_junit_fork/version'
4
+
5
+ module Fastlane
6
+ module XcresultToJunit
7
+ # Return all .rb files inside the "actions" and "helper" directory
8
+ def self.all_classes
9
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
10
+ end
11
+ end
12
+ end
13
+
14
+ # By default we want to import all available actions and helpers
15
+ # A plugin can contain any number of actions and plugins
16
+ Fastlane::XcresultToJunit.all_classes.each do |current|
17
+ require current
18
+ end
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'fastlane/action'
5
+ require_relative '../helper/xcresult_to_junit_helper'
6
+
7
+ module Fastlane
8
+ module Actions
9
+ class XcresultToJunitAction < Action
10
+ def self.run(params)
11
+ UI.message('The xcresult_to_junit plugin has started!')
12
+ result = Helper::XcresultToJunitHelper.fetch_tests(params[:xcresult_path])
13
+
14
+ devices = result['devices']
15
+ test_plans = result['testNodes']
16
+
17
+ devices.each do |device|
18
+ map = {}
19
+ junit_folder = Helper::XcresultToJunitHelper.save_device_details_to_file(params[:output_path], [device])
20
+ test_suites = []
21
+
22
+ test_plans.each do |test_plan|
23
+ test_plan['children'].each do |test_bundle|
24
+ test_bundle['children'].each do |test_suite|
25
+ suite_name = test_suite['name']
26
+ count = 0
27
+ passed = 0
28
+ failed = 0
29
+ test_cases = []
30
+ test_suite['children'].each do |test_case|
31
+ duration = 0.0
32
+ duration = test_case['duration'].sub('s', '').to_f if test_case['duration']
33
+ full_testcase_name = test_case['name'].sub('()', '')
34
+ tags = full_testcase_name.split('_')[1..]
35
+ testcase = { name: full_testcase_name, time: duration }
36
+ count += 1
37
+ if test_case['result'] == 'Passed'
38
+ passed += 1
39
+ elsif test_case['result'] == 'Failed'
40
+ failed += 1
41
+ testcase[:failure] ||= []
42
+ testcase[:failure_location] ||= []
43
+ test_case['children'].each do |failure|
44
+ if failure['nodeType'] == 'Repetition'
45
+ failure['children'].each do |retry_failure|
46
+ testcase[:failure] << retry_failure['name']
47
+ testcase[:failure_location] << failure['name']
48
+ end
49
+ elsif failure['nodeType'] == 'Failure Message'
50
+ testcase[:failure] << failure['name']
51
+ testcase[:failure_location] << failure['name'].split(': ')[0]
52
+ end
53
+ end
54
+ end
55
+ test_cases << testcase
56
+ map["#{suite_name}.#{full_testcase_name}"] = { 'files' => [], 'tags' => tags }
57
+ end
58
+ suite = { name: suite_name.to_s, count: count, failures: failed, errors: 0, cases: test_cases }
59
+ test_suites << suite
60
+ end
61
+ end
62
+ end
63
+
64
+ Helper::XcresultToJunitHelper.generate_junit(junit_folder, test_suites)
65
+ attachments_folder = "#{junit_folder}/attachments"
66
+ Helper::XcresultToJunitHelper.save_attachments(params[:xcresult_path], attachments_folder)
67
+
68
+ test_attachments = Helper::XcresultToJunitHelper.fetch_attachment_manifest(attachments_folder)
69
+
70
+ test_attachments.each do |test_attachment|
71
+ test_identifier = test_attachment['testIdentifier']
72
+ folder_name = test_identifier.sub('()', '').sub('/', '.')
73
+
74
+ test_attachment['attachments'].reverse().each do |attachment|
75
+ name = attachment['suggestedHumanReadableName']
76
+ filename = attachment['exportedFileName']
77
+ mime_type = 'image/png'
78
+ mime_type = 'text/plain' if filename.end_with?('.txt')
79
+ timestamp = attachment['timestamp']
80
+ map[folder_name] ||= { 'files' => [] }
81
+ map[folder_name]['files'].push({ 'description' => name, 'mime-type' => mime_type, 'path' => filename,
82
+ 'timestamp' => timestamp })
83
+ end
84
+ end
85
+
86
+ Helper::XcresultToJunitHelper.save_screenshot_mapping(map, attachments_folder)
87
+ end
88
+ UI.message('The xcresult_to_junit plugin has finished!')
89
+ end
90
+
91
+ def self.description
92
+ 'Produces junit xml files from Xcode 11+ xcresult files'
93
+ end
94
+
95
+ def self.authors
96
+ ['Shane Birdsall']
97
+ end
98
+
99
+ def self.return_value
100
+ # If your method provides a return value, you can describe here what it does
101
+ end
102
+
103
+ def self.details
104
+ 'By using the xcresulttool this plugin parses xcresult files and generates junit reports to be used with other tools to display iOS test results'
105
+ end
106
+
107
+ def self.available_options
108
+ [
109
+ FastlaneCore::ConfigItem.new(key: :xcresult_path,
110
+ env_name: 'XCRESULT_TO_JUNIT_XCRESULT_PATH',
111
+ description: 'The path to the xcresult file',
112
+ optional: false,
113
+ type: String),
114
+ FastlaneCore::ConfigItem.new(key: :output_path,
115
+ env_name: 'XCRESULT_TO_JUNIT_OUTPUT_PATH',
116
+ description: 'The path where the output will be placed',
117
+ optional: false,
118
+ type: String)
119
+ ]
120
+ end
121
+
122
+ def self.is_supported?(platform)
123
+ %i[ios mac].include?(platform)
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fastlane_core/ui/ui'
4
+ require 'json'
5
+ require 'fileutils'
6
+
7
+ module Fastlane
8
+ UI = FastlaneCore::UI unless Fastlane.const_defined?('UI')
9
+
10
+ module Helper
11
+ class XcresultToJunitHelper
12
+ def self.fetch_tests(xcresult_path)
13
+ JSON.parse(FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get test-results tests --path #{xcresult_path}"))
14
+ end
15
+
16
+ def self.save_attachments(xcresult_path, output_path)
17
+ FileUtils.mkdir(output_path) unless File.directory?(output_path)
18
+ FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool export attachments --path #{xcresult_path} --output-path #{output_path}")
19
+ end
20
+
21
+ def self.fetch_attachment_manifest(attachments_folder)
22
+ JSON.parse(FastlaneCore::CommandExecutor.execute(command: "cat #{attachments_folder}/manifest.json"))
23
+ end
24
+
25
+ def self.save_screenshot_mapping(map_hash, output_path)
26
+ File.open("#{output_path}/map.json", 'w') do |f|
27
+ f << map_hash.to_json
28
+ end
29
+ end
30
+
31
+ def self.save_device_details_to_file(output_path, devices)
32
+ device = devices[0]
33
+ device_details = {
34
+ 'architecture' => device['architecture'],
35
+ 'udid' => device['deviceId'],
36
+ 'name' => device['deviceName'],
37
+ 'model' => device['modelName'],
38
+ 'os' => device['osVersion'],
39
+ 'platform' => device['platform']
40
+ }.to_json
41
+
42
+ junit_folder = "#{output_path}/ios-#{device['deviceId']}.junit"
43
+ FileUtils.rm_rf(junit_folder)
44
+ FileUtils.mkdir_p("#{junit_folder}/attachments")
45
+ File.open("#{junit_folder}/device.json", 'w') do |f|
46
+ f << device_details
47
+ end
48
+ junit_folder
49
+ end
50
+
51
+ def self.junit_file_start
52
+ puts('<?xml version="1.0" encoding="UTF-8"?>')
53
+ puts('<testsuites>')
54
+ end
55
+
56
+ def self.junit_file_end
57
+ puts('</testsuites>')
58
+ end
59
+
60
+ def self.junit_suite_error(suite)
61
+ puts("<testsuite name=#{suite[:name].encode(xml: :attr)} errors='1'>")
62
+ puts("<error>#{suite[:error].encode(xml: :text)}</error>")
63
+ end
64
+
65
+ def self.junit_suite_start(suite)
66
+ puts("<testsuite name=#{suite[:name].encode(xml: :attr)} tests='#{suite[:count]}' failures='#{suite[:failures]}' errors='#{suite[:errors]}'>")
67
+ end
68
+
69
+ def self.junit_suite_end
70
+ puts('</testsuite>')
71
+ end
72
+
73
+ def self.junit_testcase_start(suite, testcase)
74
+ print("<testcase name=#{testcase[:name].encode(xml: :attr)} classname=#{suite[:name].encode(xml: :attr)} time='#{testcase[:time]}'>")
75
+ end
76
+
77
+ def self.junit_testcase_end
78
+ puts('</testcase>')
79
+ end
80
+
81
+ def self.junit_testcase_failure(testcase)
82
+ if testcase[:failure].length != testcase[:failure_location].length
83
+ raise "Mismatch in lengths: testcase[:failure] and testcase[:failure_location] must have the same length."
84
+ end
85
+ for index in 0...testcase[:failure].length
86
+ failure = testcase[:failure][index]
87
+ failure_location = testcase[:failure_location][index]
88
+ puts("<failure message=#{failure.encode(xml: :attr)}>#{failure_location.encode(xml: :text)}</failure>")
89
+ end
90
+ end
91
+
92
+ def self.junit_testcase_error(testcase)
93
+ puts("<error>#{testcase[:error].encode(xml: :text)}</error>")
94
+ end
95
+
96
+ def self.junit_testcase_performance(testcase)
97
+ puts("<system-out>#{testcase[:performance]}</system-out>")
98
+ end
99
+
100
+ def self.generate_junit(junit_folder, test_suites)
101
+ File.open("#{junit_folder}/results.xml", 'w') do |fo|
102
+ old_stdout = $stdout
103
+ $stdout = fo
104
+ Helper::XcresultToJunitHelper.junit_file_start
105
+ test_suites.each do |suite|
106
+ if suite[:error]
107
+ Helper::XcresultToJunitHelper.junit_suite_error(suite)
108
+ else
109
+ Helper::XcresultToJunitHelper.junit_suite_start(suite)
110
+ suite[:cases].each do |testcase|
111
+ Helper::XcresultToJunitHelper.junit_testcase_start(suite, testcase)
112
+ if testcase[:failure]
113
+ Helper::XcresultToJunitHelper.junit_testcase_failure(testcase)
114
+ elsif testcase[:error]
115
+ Helper::XcresultToJunitHelper.junit_testcase_error(testcase)
116
+ end
117
+ Helper::XcresultToJunitHelper.junit_testcase_performance(testcase) if testcase[:performance]
118
+ Helper::XcresultToJunitHelper.junit_testcase_end
119
+ end
120
+ end
121
+ Helper::XcresultToJunitHelper.junit_suite_end
122
+ end
123
+ Helper::XcresultToJunitHelper.junit_file_end
124
+ $stdout = old_stdout
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fastlane
4
+ module XcresultToJunit
5
+ VERSION = '0.4.4'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-xcresult_to_junit_fork
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.4
5
+ platform: ruby
6
+ authors:
7
+ - Jack Hosking
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.49.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.49.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-require_tools
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email: jack.hosking@fiserv.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - LICENSE
132
+ - README.md
133
+ - lib/fastlane/plugin/xcresult_to_junit.rb
134
+ - lib/fastlane/plugin/xcresult_to_junit_fork/actions/xcresult_to_junit_action.rb
135
+ - lib/fastlane/plugin/xcresult_to_junit_fork/helper/xcresult_to_junit_helper.rb
136
+ - lib/fastlane/plugin/xcresult_to_junit_fork/version.rb
137
+ homepage: https://github.com/zanizrules/fastlane-plugin-xcresult_to_junit
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubygems_version: 3.4.10
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: 'A Fork of fastlane-plugin-xcresult_to_junit: Produces junit xml files from
160
+ Xcode 11+ xcresult files'
161
+ test_files: []