A platform for community discussion. Free, open, simple.
DEV: Summarize JS deprecations at end of system spec run (#24824)
David Taylor6731eec42ab1
diff --git a/lib/turbo_tests/base_formatter.rb b/lib/turbo_tests/base_formatter.rbindex ab715a11def..e3139a9a00f 100644--- a/lib/turbo_tests/base_formatter.rb+++ b/lib/turbo_tests/base_formatter.rb@@ -17,6 +17,35 @@ module TurboTestsendend+ js_deprecation_totals = {}+ notification.examples.each do |example|+ example.metadata[:js_deprecations]&.each do |id, count|+ js_deprecation_totals[id] ||= 0+ js_deprecation_totals[id] += count+ end+ end++ if js_deprecation_totals.present?+ max_id_length = js_deprecation_totals.keys.map(&:length).max+ output.puts "\n[Deprecation Counter] Test run completed with deprecations:\n\n"++ table = ""+ table += "| #{"id".ljust(max_id_length)} | count |\n"+ table += "| #{"-" * max_id_length} | ----- |\n"+ js_deprecation_totals.each do |id, count|+ table += "| #{id.ljust(max_id_length)} | #{count.to_s.ljust(5)} |\n"+ end++ output.puts table++ if ENV["GITHUB_ACTIONS"] && ENV["GITHUB_STEP_SUMMARY"]+ job_summary = "### ⚠️ JS Deprecations\n\nTest run completed with deprecations:\n\n"+ job_summary += table+ job_summary += "\n\n"+ File.write(ENV["GITHUB_STEP_SUMMARY"], job_summary)+ end+ end+super(notification)endenddiff --git a/lib/turbo_tests/json_example.rb b/lib/turbo_tests/json_example.rbindex 77bbd1b87af..e3eb6e35f4b 100644--- a/lib/turbo_tests/json_example.rb+++ b/lib/turbo_tests/json_example.rb@@ -19,6 +19,7 @@ module TurboTestsextra_failure_lines: @rspec_example.metadata[:extra_failure_lines],run_duration_ms: @rspec_example.metadata[:run_duration_ms],process_pid: Process.pid,+ js_deprecations: @rspec_example.metadata[:js_deprecations],},location_rerun_argument: @rspec_example.location_rerun_argument,}diff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex f66c5939acc..b264f56779c 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -377,7 +377,7 @@ RSpec.configure do |config|end# possible values: OFF, SEVERE, WARNING, INFO, DEBUG, ALL- browser_log_level = ENV["SELENIUM_BROWSER_LOG_LEVEL"] || "SEVERE"+ browser_log_level = ENV["SELENIUM_BROWSER_LOG_LEVEL"] || "WARNING"chrome_browser_options =Selenium::WebDriver::Chrome::Options@@ -531,6 +531,8 @@ RSpec.configure do |config|lines << "~~~~~ END DRIVER LOGS ~~~~~"end+ js_logs = page.driver.browser.logs.get(:browser)+# Recommended that this is not disabled, since it makes debugging# failed system tests a lot trickier.if ENV["SELENIUM_DISABLE_VERBOSE_JS_LOGS"].blank?@@ -547,11 +549,10 @@ RSpec.configure do |config|if !skip_js_errorslines << "~~~~~~~ JS LOGS ~~~~~~~"- logs = page.driver.browser.logs.get(:browser)- if logs.empty?+ if js_logs.empty?lines << "(no logs)"else- logs.each do |log|+ js_logs.each do |log|# System specs are full of image load errors that are just noise, no need# to log this.if (@@ -569,6 +570,16 @@ RSpec.configure do |config|endend+ js_logs.each do |log|+ next if log.level != "WARNING"+ deprecation_id = log.message[/\[deprecation id: ([^\]]+)\]/, 1]+ next if deprecation_id.nil?++ deprecations = RSpec.current_example.metadata[:js_deprecations] ||= {}+ deprecations[deprecation_id] ||= 0+ deprecations[deprecation_id] += 1+ end+page.execute_script("if (typeof MessageBus !== 'undefined') { MessageBus.stop(); }")MessageBus.backend_instance.reset! # Clears all existing backlog from memory backendScheduler::Defer.do_all_work # Process everything that was added to the defer queue when running the test