class Minitest::Queue::TestTimeReporter

Attributes

limit[R]
percentile[R]
test_time_hash[R]

Public Class Methods

new(build:, limit: nil, percentile: nil, **options) click to toggle source
Calls superclass method
# File lib/minitest/queue/test_time_reporter.rb, line 9
def initialize(build:, limit: nil, percentile: nil, **options)
  super(options)
  @test_time_hash = build.fetch
  @limit = limit
  @percentile = percentile
  @success = true
end

Public Instance Methods

record(*) click to toggle source
# File lib/minitest/queue/test_time_reporter.rb, line 42
def record(*)
  raise NotImplementedError
end
report() click to toggle source
# File lib/minitest/queue/test_time_reporter.rb, line 17
      def report
        return if limit.nil? || test_time_hash.empty?

        puts '+++ Test Time Report'

        if offending_tests.empty?
          msg = "The #{humanized_percentile} of test execution time is within #{limit} milliseconds."
          puts green(msg)
          return
        end

        @success = false
        puts <<~EOS
          #{red("Detected #{offending_tests.size} test(s) over the desired time limit.")}
          Please make them faster than #{limit}ms in the #{humanized_percentile} percentile.
        EOS
        offending_tests.each do |test_name, duration|
          puts "#{red(test_name)}: #{duration}ms"
        end
      end
success?() click to toggle source
# File lib/minitest/queue/test_time_reporter.rb, line 38
def success?
  @success
end

Private Instance Methods

calculate_percentile(array) click to toggle source
# File lib/minitest/queue/test_time_reporter.rb, line 65
def calculate_percentile(array)
  array.sort[(percentile * array.length).ceil - 1]
end
humanized_percentile() click to toggle source
# File lib/minitest/queue/test_time_reporter.rb, line 50
def humanized_percentile
  percentile_in_percentage = percentile * 100
  "#{percentile_in_percentage.to_i}th"
end
offending_tests() click to toggle source
# File lib/minitest/queue/test_time_reporter.rb, line 55
def offending_tests
  @offending_tests ||= begin
    test_time_hash.each_with_object({}) do |(test_name, durations), offenders|
      duration = calculate_percentile(durations)
      next if duration <= limit
      offenders[test_name] = duration
    end
  end
end