Class: Fastlane::Actions::CollateHtmlReportsAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::CollateHtmlReportsAction
- Defined in:
- lib/fastlane/plugin/test_center/actions/collate_html_reports.rb
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
-
.description ⇒ Object
:nocov:.
- .details ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
Class Method Summary collapse
- .opened_reports(report_filepaths) ⇒ Object
- .repair_malformed_html(html_report_filepath) ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
122 123 124 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 122 def self. ["lyndsey-ferguson/@lyndseydf"] end |
.available_options ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 80 def self. [ FastlaneCore::ConfigItem.new( key: :reports, env_name: 'COLLATE_HTML_REPORTS_REPORTS', description: 'An array of HTML reports to collate. The first report is used as the base into which other reports are merged in', optional: false, type: Array, verify_block: proc do |reports| UI.user_error!('No HTML report files found') if reports.empty? reports.each do |report| UI.user_error!("Error: HTML report not found: '#{report}'") unless File.exist?(report) end end ), FastlaneCore::ConfigItem.new( key: :collated_report, env_name: 'COLLATE_HTML_REPORTS_COLLATED_REPORT', description: 'The final HTML report file where all testcases will be merged into', optional: true, default_value: 'result.html', type: String ) ] end |
.category ⇒ Object
130 131 132 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 130 def self.category :testing end |
.description ⇒ Object
:nocov:
65 66 67 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 65 def self.description "🔶 Combines multiple html report files into one html report file" end |
.details ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 69 def self.details "The first HTML report is used as the base report. Testcases " \ "from other reports are added if they do not already exist, or " \ "if the testcases already exist, they are replaced." \ "" \ "This is done because it is assumed that fragile tests, when " \ "re-run will often succeed due to less interference from other " \ "tests and the subsequent HTML reports will have more passed tests." \ "" end |
.example_code ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 106 def self.example_code [ " UI.important( 'example: ' \\ 'collate the html reports to a temporary file \"result.html\"' ) reports = Dir['../spec/fixtures/*.html'].map { |relpath| File.absolute_path(relpath) } collate_html_reports( reports: reports, collated_report: File.join(Dir.mktmpdir, 'result.html') ) " ] end |
.is_supported?(platform) ⇒ Boolean
126 127 128 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 126 def self.is_supported?(platform) %i[ios mac].include?(platform) end |
.opened_reports(report_filepaths) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 22 def self.opened_reports(report_filepaths) report_filepaths.map do |report_filepath| report = nil repair_attempted = false begin report = ::TestCenter::Helper::HtmlTestReport::Report.new(REXML::Document.new(File.new(report_filepath))) rescue REXML::ParseException => e if repair_attempted UI.important("'#{report_filepath}' is malformed and :collate_html_reports cannot repair it") raise e else UI.important("'#{report_filepath}' is malformed. Attempting to repair it") repair_attempted = true repair_malformed_html(report_filepath) retry end end report end end |
.repair_malformed_html(html_report_filepath) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 43 def self.repair_malformed_html(html_report_filepath) html_file_contents = File.read(html_report_filepath) File.open(html_report_filepath, 'w') do |file| html_file_contents.each_line do |line| m = %r{(<section class="test-detail[^"]*">)(.*(<|>|&(?!amp;)).*)(</section>)}.match(line) if m test_details = m[2] test_details.gsub!(/&(?!amp;)/, '&') test_details.gsub!('<', '<') test_details.gsub!('>', '>') line = m[1] + test_details + m[4] end file.puts line end end end |
.run(params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fastlane/plugin/test_center/actions/collate_html_reports.rb', line 4 def self.run(params) report_filepaths = params[:reports] if report_filepaths.size == 1 FileUtils.cp(report_filepaths[0], params[:collated_report]) else reports = opened_reports(report_filepaths) # copy any missing testsuites target_report = reports.shift reports.each do |report| target_report.collate_report(report) end FileUtils.mkdir_p(File.dirname(params[:collated_report])) target_report.save_report(params[:collated_report]) end end |