diff --git a/README.md b/README.md index f5a285a..c850cb2 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,12 @@ Options: --seed SEED Seed for rspec ``` +To pass any options supported by paralell_tests, use `--` : + +```bash +bundle exec turbo_tests -n 4 -- --only-group 1 --pattern spec/system +``` + ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. diff --git a/lib/turbo_tests/cli.rb b/lib/turbo_tests/cli.rb index 6f033cc..d914060 100644 --- a/lib/turbo_tests/cli.rb +++ b/lib/turbo_tests/cli.rb @@ -98,15 +98,19 @@ def run end end + parallel_options = ParallelTests::CLI.new.send(:parse_options!, @argv.unshift("--type", "rspec")) + files = parallel_options.fetch(:files, ["spec"]) + exitstatus = TurboTests::Runner.run( formatters: formatters, tags: tags, - files: @argv.empty? ? ["spec"] : @argv, + files: files, runtime_log: runtime_log, verbose: verbose, fail_fast: fail_fast, count: count, - seed: seed + seed: seed, + parallel_options: parallel_options ) # From https://github.com/serpapi/turbo_tests/pull/20/ diff --git a/lib/turbo_tests/runner.rb b/lib/turbo_tests/runner.rb index 026d593..4475fbe 100644 --- a/lib/turbo_tests/runner.rb +++ b/lib/turbo_tests/runner.rb @@ -13,6 +13,7 @@ def self.run(opts = {}) files = opts[:files] formatters = opts[:formatters] tags = opts[:tags] + parallel_options = opts[:parallel_options] start_time = opts.fetch(:start_time) { RSpec::Core::Time.now } runtime_log = opts.fetch(:runtime_log, nil) @@ -38,6 +39,7 @@ def self.run(opts = {}) count: count, seed: seed, seed_used: seed_used, + parallel_options: parallel_options ).run end @@ -45,7 +47,6 @@ def initialize(opts) @reporter = opts[:reporter] @files = opts[:files] @tags = opts[:tags] - @runtime_log = opts[:runtime_log] || "tmp/turbo_rspec_runtime.log" @verbose = opts[:verbose] @fail_fast = opts[:fail_fast] @count = opts[:count] @@ -56,6 +57,10 @@ def initialize(opts) @load_count = 0 @failure_count = 0 + @runtime_log = opts[:runtime_log] || "tmp/turbo_rspec_runtime.log" + @parallel_options = opts.fetch(:parallel_options, {}) + @parallel_options[:runtime_log] = @runtime_log + @messages = Thread::Queue.new @threads = [] @error = false @@ -67,25 +72,15 @@ def run ParallelTests::RSpec::Runner.tests_with_size(@files, {}).size ].min - use_runtime_info = @files == ["spec"] - - group_opts = {} - - if use_runtime_info - group_opts[:runtime_log] = @runtime_log - else - group_opts[:group_by] = :filesize - end - tests_in_groups = ParallelTests::RSpec::Runner.tests_in_groups( @files, @num_processes, - **group_opts + @parallel_options ) subprocess_opts = { - record_runtime: use_runtime_info, + record_runtime: @parallel_options[:group_by] == :runtime } @reporter.report(tests_in_groups) do |reporter|