Skip to content

Commit

Permalink
Prototyping for custom test reporter [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Feb 12, 2025
1 parent d88a6d9 commit 93c2d6d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/minitest/reporters/ruby_lsp_reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# typed: strict
# frozen_string_literal: true

module Minitest
module Reporters
class RubyLspReporter < BaseReporter
def initialize(options = {})
# TODO
super
end

def start
# TODO
super
end

def before_test(test)
# TODO
super
end

def record(test)
result = {
classname: test.klass,
file: test.source_location[0],
line: test.source_location[1],
time: test.time,
}
if (failure = test.failure)
result[:failure] = {
type: failure.class.name,
message: failure.message, # TODO: truncate?
}
end

if test.skipped?
result[:skipped] = {
message: "TODO: skip reason",
}
end

puts result.to_json
# TODO: flush IO after each?

super # need?
end

def report
# TODO
super
end
end
end
end
2 changes: 2 additions & 0 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_detects_no_test_library_when_there_are_no_dependencies
end

def test_detects_minitest
raise "x" # temporary to verify test reporter
stub_direct_dependencies("minitest" => "1.2.3")

state = GlobalState.new
Expand All @@ -22,6 +23,7 @@ def test_detects_minitest
end

def test_does_not_detect_minitest_related_gems_as_minitest
skip("no thank you") # temporary to verify test reporter
stub_direct_dependencies("minitest-reporters" => "1.2.3")

state = GlobalState.new
Expand Down
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
end
Minitest::Reporters.use!(minitest_reporter)

if ENV["RUBY_LSP"]
require "minitest/reporters/ruby_lsp_reporter"
Minitest::Reporters.use!(Minitest::Reporters::RubyLspReporter.new)
end

module Minitest
class Test
extend T::Sig
Expand Down

0 comments on commit 93c2d6d

Please sign in to comment.