Class: Minitest::Queue::GrindReporter

Inherits:
Reporters::BaseReporter
  • Object
show all
Includes:
CI::Queue::OutputHelpers
Defined in:
lib/minitest/queue/grind_reporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(build:, **options) ⇒ GrindReporter

Returns a new instance of GrindReporter.



9
10
11
12
13
# File 'lib/minitest/queue/grind_reporter.rb', line 9

def initialize(build:, **options)
  @build = build
  @success = true
  super(options)
end

Instance Method Details

#fetch_counts(test) ⇒ Object



64
65
66
67
# File 'lib/minitest/queue/grind_reporter.rb', line 64

def fetch_counts(test)
  key = "count##{test}"
  build.fetch_stats([key])[key]
end

#flaky_testsObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/minitest/queue/grind_reporter.rb', line 47

def flaky_tests
  @flaky_tests ||= begin
    flaky_tests = {}
    build.error_reports.each do |error|
      err = ErrorReport.load(error)
      name = err.test_and_module_name
      flaky_tests[name] ||= []
      flaky_tests[name] << err
    end
    flaky_tests
  end
end

#recordObject

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/minitest/queue/grind_reporter.rb', line 60

def record(*)
  raise NotImplementedError
end

#reportObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/minitest/queue/grind_reporter.rb', line 15

def report
  puts '+++ Results'

  if flaky_tests.empty?
    puts green('all tests passed every time, grinding did not uncover any flakiness')
    return
  end
  @success = false

  flaky_tests.each do |name, errors|
    total_runs = fetch_counts(name)
    flakiness_percentage = (errors.count / total_runs) * 100

    error_messages = errors.map do |message|
      message.to_s.lines.map { |l| "\t#{l}"}.join
    end.to_set.to_a.join("\n\n")

    puts <<~EOS
      #{red(name)}
      Runs: #{total_runs.to_i}
      Failures: #{errors.count}
      Flakiness Percentage: #{flakiness_percentage.to_i}%
      Errors:
      #{error_messages}
    EOS
  end
end

#success?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/minitest/queue/grind_reporter.rb', line 43

def success?
  @success
end