# frozen_string_literal: truerequire"parallel_tests/test/runner"moduleParallelTestsmoduleGherkinclassRunner<ParallelTests::Test::Runnerclass<<selfdefrun_tests(test_files,process_number,num_processes,options)combined_scenarios=test_filesifoptions[:group_by]==:scenariosgrouped=test_files.map{|t|t.split(':')}.group_by(&:first)combined_scenarios=grouped.mapdo|file,files_and_lines|"#{file}:#{files_and_lines.map(&:last).join(':')}"endendoptions[:env]||={}options[:env]=options[:env].merge({'AUTOTEST'=>'1'})if$stdout.tty?execute_command(build_command(combined_scenarios,options),process_number,num_processes,options)enddeftest_file_name@test_file_name||'feature'enddefdefault_test_folder'features'enddeftest_suffix/\.feature$/enddefline_is_result?(line)line=~/^\d+ (steps?|scenarios?)/enddefbuild_test_command(file_list,options)[*executable,*(runtime_loggingifFile.directory?(File.dirname(runtime_log))),*file_list,*cucumber_opts(options[:test_options])]end# cucumber has 2 result lines per test run, that cannot be added# 1 scenario (1 failed)# 1 step (1 failed)defsummarize_results(results)sort_order=['scenario','step','failed','flaky','undefined','skipped','pending','passed']['scenario','step'].mapdo|group|group_results=results.grep(/^\d+ #{group}/)nextifgroup_results.empty?sums=sum_up_results(group_results)sums=sums.sort_by{|word,_|sort_order.index(word)||999}sums.map!do|word,number|plural="s"if(word==group)&&(number!=1)"#{number}#{word}#{plural}"end"#{sums[0]} (#{sums[1..].join(", ")})"end.compact.join("\n")enddefcucumber_opts(given)ifgiven&.include?('--profile')||given&.include?('-p')givenelse[*given,*profile_from_config]endenddefprofile_from_config# copied from https://github.com/cucumber/cucumber/blob/master/lib/cucumber/cli/profile_loader.rb#L85config=Dir.glob("{,.config/,config/}#{name}{.yml,.yaml}").first['--profile','parallel']ifconfig&&File.read(config)=~/^parallel:/enddeftests_in_groups(tests,num_groups,options={})@test_file_name="scenario"ifoptions[:group_by]==:scenariosmethod="by_#{options[:group_by]}"ifGrouper.respond_to?(method)Grouper.send(method,find_tests(tests,options),num_groups,options)elsesuperendenddefruntime_logging['--format','ParallelTests::Gherkin::RuntimeLogger','--out',runtime_log]enddefruntime_log"tmp/parallel_runtime_#{name}.log"enddefdetermine_executableifFile.exist?("bin/#{name}")ParallelTests.with_ruby_binary("bin/#{name}")elsifParallelTests.bundler_enabled?["bundle","exec",name]elsifFile.file?("script/#{name}")ParallelTests.with_ruby_binary("script/#{name}")else[name.to_s]endendendendendend