lib/junit/plugin.rb in danger-junit-1.0.0 vs lib/junit/plugin.rb in danger-junit-1.0.1

- old
+ new

@@ -90,10 +90,17 @@ # or all of the common attributes between multiple files # # @return [Array<Symbol>] attr_accessor :headers + # An array of symbols that become the columns of your skipped tests, + # if `nil`, the default, it will be all of the attributes for a single parse + # or all of the common attributes between multiple files + # + # @return [Array<Symbol>] + attr_accessor :skipped_headers + # Parses an XML file, which fills all the attributes, # will `raise` for errors # @return [void] def parse(file) parse_files(file) @@ -118,11 +125,11 @@ failed_suites = suite_root.nodes.select { |suite| suite[:failures].to_i > 0 || suite[:errors].to_i > 0 } failed_tests += failed_suites.map(&:nodes).flatten.select { |node| node.kind_of?(Ox::Element) && node.value == 'testcase' } end - @failures = failed_tests.select do |test| + @failures = failed_tests.select do |test| test.nodes.count > 0 end.select do |test| node = test.nodes.first node.kind_of?(Ox::Element) && node.value == 'failure' end @@ -148,43 +155,54 @@ # and outputs a markdown table of the results. # # @return [void] def report return if failures.nil? # because danger calls `report` before loading a file - warn("Skipped #{skipped.count} tests.") if show_skipped_tests && skipped.count > 0 + if show_skipped_tests && skipped.count > 0 + warn("Skipped #{skipped.count} tests.") + message = "### Skipped: \n\n" + message << get_report_content(skipped, skipped_headers) + markdown message + + end + unless failures.empty? && errors.empty? fail('Tests have failed, see below for more information.', sticky: false) - message = "### Tests: \n\n" + message = "### Tests: \n\n" tests = (failures + errors) + message << get_report_content(tests, header) + markdown message + end + end - common_attributes = tests.map{|test| test.attributes.keys }.inject(&:&) + private - # check the provided headers are available - unless headers.nil? - not_available_headers = headers.select { |header| not common_attributes.include?(header) } - raise "Some of headers provided aren't available in the JUnit report (#{not_available_headers})" unless not_available_headers.empty? - end + def get_report_content(tests, headers) + message = '' + common_attributes = tests.map{|test| test.attributes.keys }.inject(&:&) - keys = headers || common_attributes - attributes = keys.map(&:to_s).map(&:capitalize) + # check the provided headers are available + unless headers.nil? + not_available_headers = headers.select { |header| not common_attributes.include?(header) } + raise "Some of headers provided aren't available in the JUnit report (#{not_available_headers})" unless not_available_headers.empty? + end - # Create the headers - message << attributes.join(' | ') + "|\n" - message << attributes.map { |_| '---' }.join(' | ') + "|\n" + keys = headers || common_attributes + attributes = keys.map(&:to_s).map(&:capitalize) - # Map out the keys to the tests - tests.each do |test| - row_values = keys.map { |key| test.attributes[key] }.map { |v| auto_link(v) } - message << row_values.join(' | ') + "|\n" - end + # Create the headers + message << attributes.join(' | ') + "|\n" + message << attributes.map { |_| '---' }.join(' | ') + "|\n" - markdown message + # Map out the keys to the tests + tests.each do |test| + row_values = keys.map { |key| test.attributes[key] }.map { |v| auto_link(v) } + message << row_values.join(' | ') + "|\n" end + message end - - private def auto_link(value) if File.exist?(value) && defined?(@dangerfile.github) github.html_link(value, full_path: false) else