Module: TestProf::FactoryProf::Printers::Json

Extended by:
Logging
Defined in:
lib/test_prof/factory_prof/printers/json.rb

Overview

:nodoc: all

Constant Summary

Constants included from Logging

Logging::COLORS

Class Method Summary collapse

Methods included from Logging

log

Class Method Details

.convert_stats(result, start_time) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/test_prof/factory_prof/printers/json.rb', line 21

def convert_stats(result, start_time)
  total_run_time = TestProf.now - start_time
  total_count = result.stats.sum { |stat| stat[:total_count] }
  total_top_level_count = result.stats.sum { |stat| stat[:top_level_count] }
  total_time = result.stats.sum { |stat| stat[:top_level_time] }
  total_uniq_factories = result.stats.map { |stat| stat[:name] }.uniq.count

  {
    total_count: total_count,
    total_top_level_count: total_top_level_count,
    total_time: total_time.duration,
    total_run_time: total_run_time.duration,
    total_uniq_factories: total_uniq_factories,

    stats: result.stats
  }
end

.dump(result, start_time:) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/test_prof/factory_prof/printers/json.rb', line 12

def dump(result, start_time:)
  return log(:info, "No factories detected") if result.raw_stats == {}

  outpath = TestProf.artifact_path("test-prof.result.json")
  File.write(outpath, convert_stats(result, start_time).to_json)

  log :info, "Profile results to JSON: #{outpath}"
end