2023-05-12 05:13:52 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module TurboTests
|
|
|
|
# An RSpec formatter that prepends the process id to all messages
|
2023-05-29 21:52:46 -04:00
|
|
|
class DocumentationFormatter < ::TurboTests::BaseFormatter
|
2024-04-03 05:54:55 -04:00
|
|
|
RSpec::Core::Formatters.register(
|
|
|
|
self,
|
|
|
|
:example_failed,
|
|
|
|
:example_passed,
|
|
|
|
:example_pending,
|
|
|
|
:start,
|
|
|
|
:stop,
|
|
|
|
)
|
|
|
|
|
|
|
|
def start(*args)
|
2024-04-03 08:27:39 -04:00
|
|
|
super(*args)
|
2024-04-03 05:54:55 -04:00
|
|
|
output.puts "::group:: Verbose turbo_spec output" if ENV["GITHUB_ACTIONS"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop(*args)
|
|
|
|
output.puts "::endgroup::" if ENV["GITHUB_ACTIONS"]
|
|
|
|
end
|
2023-05-12 05:13:52 -04:00
|
|
|
|
|
|
|
def example_passed(notification)
|
|
|
|
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
|
2023-05-29 21:52:46 -04:00
|
|
|
output_example(notification.example),
|
2023-05-12 05:13:52 -04:00
|
|
|
:success,
|
|
|
|
)
|
2023-05-29 21:52:46 -04:00
|
|
|
|
2023-12-27 01:40:00 -05:00
|
|
|
output_activerecord_debug_logs(output, notification.example)
|
|
|
|
|
2023-05-12 05:13:52 -04:00
|
|
|
output.flush
|
|
|
|
end
|
|
|
|
|
|
|
|
def example_pending(notification)
|
|
|
|
message = notification.example.execution_result.pending_message
|
2023-05-29 21:52:46 -04:00
|
|
|
|
2023-05-12 05:13:52 -04:00
|
|
|
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
|
2023-05-29 21:52:46 -04:00
|
|
|
"#{output_example(notification.example)} (PENDING: #{message})",
|
2023-05-12 05:13:52 -04:00
|
|
|
:pending,
|
|
|
|
)
|
2023-05-29 21:52:46 -04:00
|
|
|
|
2023-05-12 05:13:52 -04:00
|
|
|
output.flush
|
|
|
|
end
|
|
|
|
|
|
|
|
def example_failed(notification)
|
|
|
|
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
|
2023-05-29 21:52:46 -04:00
|
|
|
"#{output_example(notification.example)} (FAILED - #{next_failure_index})",
|
2023-05-12 05:13:52 -04:00
|
|
|
:failure,
|
|
|
|
)
|
2023-05-29 21:52:46 -04:00
|
|
|
|
2023-12-27 01:40:00 -05:00
|
|
|
output_activerecord_debug_logs(output, notification.example)
|
|
|
|
|
2023-05-12 05:13:52 -04:00
|
|
|
output.flush
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-12-27 01:40:00 -05:00
|
|
|
def output_activerecord_debug_logs(output, example)
|
|
|
|
if ENV["GITHUB_ACTIONS"] &&
|
|
|
|
active_record_debug_logs = example.metadata[:active_record_debug_logs]
|
|
|
|
output.puts "::group::ActiveRecord Debug Logs"
|
|
|
|
output.puts active_record_debug_logs
|
|
|
|
output.puts "::endgroup::"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-29 21:52:46 -04:00
|
|
|
def output_example(example)
|
2023-07-04 23:47:35 -04:00
|
|
|
output =
|
|
|
|
+"[#{example.process_id}] (##{example.metadata[:process_pid]}) #{example.full_description}"
|
2023-05-29 21:52:46 -04:00
|
|
|
|
|
|
|
if run_duration_ms = example.metadata[:run_duration_ms]
|
|
|
|
output << " (#{run_duration_ms}ms)"
|
|
|
|
end
|
|
|
|
|
|
|
|
output
|
|
|
|
end
|
|
|
|
|
2023-05-12 05:13:52 -04:00
|
|
|
def next_failure_index
|
|
|
|
@next_failure_index ||= 0
|
|
|
|
@next_failure_index += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|