Skip to content

Commit

Permalink
Add notes on custom slowest-minitest reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Nov 3, 2024
1 parent 1a4233d commit 3993b5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions docs/notes/slowest-minitest-reporter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

Tried creating a minitest-reporter to print the slowest times, so I can simplify id58_test_base.rb
Problem is that you can't get the filename location (filename + line-number)

class Minitest::Reporters::SlowestReporter < Minitest::Reporters::BaseReporter
def initialize(options = {})
super
self.results = []
end
attr_accessor :results
def record(result)
results << result
end
def report
super
timings = []
results.each do |result|
timings << [ result.name.gsub("\n", ''), result.time ]
end

sorted = timings.sort_by{ |name, secs| -secs }.to_h
max_shown = 5
size = sorted.size < max_shown ? sorted.size : max_shown
puts
if size != 0
puts "Slowest #{size} tests in /saver/test/ are..."
end
sorted.each.with_index { |(name,secs),index|
puts "%3.4f %-72s" % [secs,name]
if index === size
break
end
}
puts
end
end
2 changes: 1 addition & 1 deletion test/server/id58_test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def trimmed(s)
size = sorted.size < max_shown ? sorted.size : max_shown
puts
if size != 0
puts "Slowest #{size} tests in /app/test/ are..."
puts "Slowest #{size} tests are..."
end
sorted.each.with_index { |(name,secs),index|
puts "%3.4f %-72s" % [secs,name]
Expand Down

0 comments on commit 3993b5e

Please sign in to comment.