A platform for community discussion. Free, open, simple.
DEV: Add `--exclude-pattern` to `bin/turbo_rspec` (#32390)
Alan Guo Xiang Tan0252712008fc
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex 7d122980417..5e9093e76bc 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -276,8 +276,7 @@ jobs:env:CHECKOUT_TIMEOUT: 10run: |- GLOBIGNORE="plugins/chat/*";- LOAD_PLUGINS=1 RAILS_ENABLE_TEST_LOG=1 RAILS_TEST_LOG_LEVEL=error bin/turbo_rspec --use-runtime-info --profile=50 --verbose --format documentation plugins/*/spec/system+ LOAD_PLUGINS=1 RAILS_ENABLE_TEST_LOG=1 RAILS_TEST_LOG_LEVEL=error bin/turbo_rspec --exclude-pattern="plugins/chat/*" --use-runtime-info --profile=50 --verbose --format documentation plugins/*/spec/systemshell: bashtimeout-minutes: 30diff --git a/bin/turbo_rspec b/bin/turbo_rspecindex ebedb1068f5..a2589c982b7 100755--- a/bin/turbo_rspec+++ b/bin/turbo_rspec@@ -16,6 +16,7 @@ profile_print_slowest_examples_count = 10use_runtime_info = nilenable_system_tests = nilretry_and_log_flaky_tests = ENV["DISCOURSE_TURBO_RSPEC_RETRY_AND_LOG_FLAKY_TESTS"].to_s == "1"+exclude_pattern = nilOptionParser.new do |opts|@@ -65,6 +66,11 @@ OptionParseropts.on("--enable-system-tests", "Run the system tests (defaults false)") doenable_system_tests = trueend++ opts.on(+ "--exclude-pattern=pattern",+ "Exclude files that matches against the pattern using unix-style pattern matching",+ ) { |pattern| exclude_pattern = pattern }end.parse!(ARGV)@@ -76,21 +82,27 @@ if ARGV.empty?run_system_tests = !!enable_system_tests- files =- if run_system_tests- ["#{Rails.root}/spec"]- else- TurboTests::Runner.default_spec_folders- end+ files = Dir.glob("#{Rails.root}/spec/**/*_spec.rb")+ files.reject! { |file| File.fnmatch("*spec/system*", file) } if !run_system_testsuse_runtime_info = true if use_runtime_info.nil?elseSTDERR.puts "Ignoring system test options since files were specified" if enable_system_tests- files = ARGV+ files =+ ARGV.flat_map do |arg|+ if File.directory?(arg)+ Dir.glob("#{arg}/**/*_spec.rb")+ else+ arg+ end+ end+use_runtime_info = false if use_runtime_info.nil?end+files.reject! { |file| File.fnmatch(exclude_pattern, file) } if exclude_pattern+requires.each { |f| require(f) }formatters << { name: "progress", outputs: [] } if formatters.empty?diff --git a/lib/turbo_tests/runner.rb b/lib/turbo_tests/runner.rbindex 41f9c2bbcae..7b8518b80f8 100644--- a/lib/turbo_tests/runner.rb+++ b/lib/turbo_tests/runner.rb@@ -42,14 +42,6 @@ module TurboTests).runend- def self.default_spec_folders- # We do not want to include system specs by default, they are quite slow.- Dir- .entries("#{Rails.root}/spec")- .reject { |entry| !File.directory?("spec/#{entry}") || %w[.. . system].include?(entry) }- .map { |entry| "spec/#{entry}" }- end-def initialize(opts)@reporter = opts[:reporter]@files = opts[:files]