Skip to content

Commit

Permalink
Calculate examples count when Reporter starts
Browse files Browse the repository at this point in the history
  • Loading branch information
inkstak committed Apr 11, 2024
1 parent e1f8f6b commit 6bfb97b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/turbo_tests/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def initialize(start_time, files, parallel_options)
end

def add(name, outputs)
custom_formatters = false
outputs.each do |output|
formatter_class =
case name
Expand All @@ -45,11 +46,18 @@ def add(name, outputs)
when "d", "documentation"
RSpec::Core::Formatters::DocumentationFormatter
else
custom_formatters = true
Kernel.const_get(name)
end

@formatters << formatter_class.new(output)
end

start if custom_formatters
end

def start
delegate_to_formatters(:start, RSpec::Core::Notifications::StartNotification.new(examples_count))
end

def group_started(notification)
Expand Down Expand Up @@ -123,6 +131,15 @@ def seed_notification(seed, seed_used)

protected

def examples_count
files = ParallelTests::RSpec::Runner.send(:find_tests, @files, @parallel_options)
output_file = Tempfile.new("rspec-summary")
`#{ENV.fetch("BUNDLE_BIN_PATH")} exec rspec --dry-run --format json --out='#{output_file.path}' #{files.join(" ")}`

json_summary = JSON.parse(output_file.read, symbolize_names: true)
json_summary.dig(:summary, :example_count) || 0
end

def delegate_to_formatters(method, *args)
@formatters.each do |formatter|
formatter.send(method, *args) if formatter.respond_to?(method)
Expand Down

0 comments on commit 6bfb97b

Please sign in to comment.