Skip to content

Commit

Permalink
Merge pull request #15 from davidwessman/rails-failure-screenshot
Browse files Browse the repository at this point in the history
Adds support for Rails failure screenshots
  • Loading branch information
aespinosa authored Mar 21, 2024
2 parents 20000f3 + 0d01dc4 commit 13bcb91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/minitest/junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def format(result, parent = nil)
testcase['file'] = relative_to_cwd(result.source_location.first)
testcase['line'] = result.source_location.last
testcase['assertions'] = result.assertions

if result.skipped?
skipped = Ox::Element.new('skipped')
skipped['message'] = result
Expand All @@ -76,6 +77,16 @@ def format(result, parent = nil)
end
end

# Minitest 5.19 supports metadata
# Rails 7.1 adds `failure_screenshot_path` to metadata
# Output according to Gitlab format
# https://docs.gitlab.com/ee/ci/testing/unit_test_reports.html#view-junit-screenshots-on-gitlab
if result.respond_to?("metadata") && result.metadata[:failure_screenshot_path]
screenshot = Ox::Element.new("system-out")
screenshot << "[[ATTACHMENT|#{result.metadata[:failure_screenshot_path]}]]"
testcase << screenshot
end

testcase
end

Expand Down
8 changes: 7 additions & 1 deletion test/reporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def test_formats_each_failed_result_with_a_formatter
results.each do |result|
parsed_report.xpath("//testcase[@name='#{result.name}']").any?
end
# Check if some testcase has a failure
# Check if some testcase has a failure and screenshot path
assert parsed_report.xpath("//testcase//failure").any?
assert parsed_report.xpath("//testcase//system-out").any?
end

def test_xml_nodes_has_file_and_line_attributes
Expand Down Expand Up @@ -93,6 +94,11 @@ def create_test_result(name: FakeTestName, methodname: 'test_method_name', succe
end
end.new
end

if failures.positive?
test.metadata[:failure_screenshot_path] = '/tmp/screenshot.png'
end

Minitest::Result.from test
end

Expand Down

0 comments on commit 13bcb91

Please sign in to comment.