Class: Minitest::Heat::Output::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/heat/output/map.rb

Overview

Generates the tokens to output the resulting heat map

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ Map

Returns a new instance of Map.



10
11
12
13
# File 'lib/minitest/heat/output/map.rb', line 10

def initialize(results)
  @results = results
  @tokens = []
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



8
9
10
# File 'lib/minitest/heat/output/map.rb', line 8

def results
  @results
end

Instance Method Details

#tokensObject



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
42
43
44
45
46
47
48
49
# File 'lib/minitest/heat/output/map.rb', line 15

def tokens
  results.heat_map.file_hits.each do |hit|
    # Focus on the relevant issues based on most significant problems. i.e. If there are
    # legitimate failures or errors, skips and slows aren't relevant
    next unless relevant_issue_types?(hit)

    # Add a new line
    @tokens << [[:muted, ""]]

    # Build the summary line for the file
    @tokens << file_summary_tokens(hit)

    # Get the set of line numbers that appear more than once
    repeated_line_numbers = find_repeated_line_numbers_in(hit)

    # Only display more details if the same line number shows up more than once
    next unless repeated_line_numbers.any?

    repeated_line_numbers.each do |line_number|
      # Get the backtraces for the given line numbers
      traces = hit.lines[line_number.to_s]

      # If there aren't any traces there's no way to provide additional details
      break unless traces.any?

      # A short summary explaining the details that will follow
      @tokens << [[:default, "  Line #{line_number}"], [:muted, ' issues triggered from:']]

      # The last relevant location for each error's backtrace
      @tokens += origination_sources(traces)
    end
  end

  @tokens
end