Commit ad6947bb authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'ml-add-json-rspec-formatter-with-extra-metadata' into 'master'

Add JSON RSpec formatter for e2e tests

See merge request gitlab-org/gitlab!38756
parents f418f720 45553100
# frozen_string_literal: true
require 'rspec/core/formatters'
module QA
module Support
class JsonFormatter < RSpec::Core::Formatters::JsonFormatter
RSpec::Core::Formatters.register self, :message, :dump_summary, :stop, :seed, :close
def dump_profile(profile)
# We don't currently use the profile info. This overrides the base
# implementation so that it's not included.
end
def stop(notification)
# Based on https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/formatters/json_formatter.rb#L35
# But modified to include full details of multiple exceptions
@output_hash[:examples] = notification.examples.map do |example|
format_example(example).tap do |hash|
e = example.exception
if e
exceptions = e.respond_to?(:all_exceptions) ? e.all_exceptions : [e]
hash[:exceptions] = exceptions.map do |exception|
{
class: exception.class.name,
message: exception.message,
backtrace: exception.backtrace
}
end
end
end
end
end
private
def format_example(example)
{
id: example.id,
description: example.description,
full_description: example.full_description,
status: example.execution_result.status.to_s,
file_path: example.metadata[:file_path],
line_number: example.metadata[:line_number],
run_time: example.execution_result.run_time,
pending_message: example.execution_result.pending_message,
status_issue: example.metadata[:status_issue],
quarantine: example.metadata[:quarantine],
screenshot: example.metadata[:screenshot]
}
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment