Skip to content

Commit

Permalink
WIP: handle Fuubar
Browse files Browse the repository at this point in the history
  • Loading branch information
inkstak committed Apr 9, 2024
1 parent ddedb01 commit 56d29b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
17 changes: 14 additions & 3 deletions lib/turbo_tests/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module TurboTests
class Reporter
attr_writer :load_time

def self.from_config(formatter_config, start_time)
reporter = new(start_time)
def self.from_config(formatter_config, start_time, files, parallel_options)
reporter = new(start_time, files, parallel_options)

formatter_config.each do |config|
name, outputs = config.values_at(:name, :outputs)
Expand All @@ -23,7 +23,7 @@ def self.from_config(formatter_config, start_time)
attr_reader :pending_examples
attr_reader :failed_examples

def initialize(start_time)
def initialize(start_time, files, parallel_options)
@formatters = []
@pending_examples = []
@failed_examples = []
Expand All @@ -32,9 +32,13 @@ def initialize(start_time)
@start_time = start_time
@load_time = 0
@errors_outside_of_examples_count = 0
@files = files
@parallel_options = parallel_options
end

def add(name, outputs)
require "fuubar" if name == "Fuubar"

outputs.each do |output|
formatter_class =
case name
Expand All @@ -48,6 +52,13 @@ def add(name, outputs)

@formatters << formatter_class.new(output)
end

if name == "Fuubar"
files = ParallelTests::RSpec::Runner.send(:find_tests, @files, @parallel_options)
output = `#{ENV.fetch("BUNDLE_BIN_PATH")} exec rspec --dry-run #{files.join(" ")} | grep 'examples, 0 failures'`
example_count = output.split(" ").first.to_i
delegate_to_formatters(:start, RSpec::Core::Notifications::StartNotification.new(example_count))
end
end

def group_started(notification)
Expand Down
28 changes: 8 additions & 20 deletions lib/turbo_tests/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,32 @@ class Runner
using CoreExtensions

def self.run(opts = {})
files = opts[:files]
formatters = opts[:formatters]
tags = opts[:tags]
parallel_options = opts[:parallel_options]

# SEE: https://bit.ly/2NP87Cz
start_time = opts.fetch(:start_time) { Process.clock_gettime(Process::CLOCK_MONOTONIC) }
runtime_log = opts.fetch(:runtime_log, nil)
verbose = opts.fetch(:verbose, false)
fail_fast = opts.fetch(:fail_fast, nil)
count = opts.fetch(:count, nil)
seed = opts.fetch(:seed) || rand(0xFFFF).to_s
seed_used = !opts[:seed].nil?

if verbose
STDERR.puts "VERBOSE"
end

reporter = Reporter.from_config(formatters, start_time)

new(
reporter: reporter,
files: files,
tags: tags,
runtime_log: runtime_log,
**opts,
start_time: start_time,
verbose: verbose,
fail_fast: fail_fast,
count: count,
seed: seed,
seed_used: seed_used,
parallel_options: parallel_options
seed_used: seed_used
).run
end

def initialize(opts)
@reporter = opts[:reporter]
def initialize(**opts)
@formatters = opts[:formatters]
@files = opts[:files]
@tags = opts[:tags]
@verbose = opts[:verbose]
@fail_fast = opts[:fail_fast]
@start_time = opts[:start_time]
@count = opts[:count]
@load_time = 0
@load_count = 0
Expand All @@ -67,6 +53,8 @@ def initialize(opts)
end

def run
@reporter = Reporter.from_config(@formatters, @start_time, @files, @parallel_options)

@num_processes = [
ParallelTests.determine_number_of_processes(@count),
ParallelTests::RSpec::Runner.tests_with_size(@files, {}).size
Expand Down

0 comments on commit 56d29b3

Please sign in to comment.