From 6731eec42ab1b89ed12afb6e899ef36cafda5a53 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 13 Dec 2023 16:04:25 +0000 Subject: [PATCH] DEV: Summarize JS deprecations at end of system spec run (#24824) --- lib/turbo_tests/base_formatter.rb | 29 +++++++++++++++++++++++++++++ lib/turbo_tests/json_example.rb | 1 + spec/rails_helper.rb | 19 +++++++++++++++---- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/turbo_tests/base_formatter.rb b/lib/turbo_tests/base_formatter.rb index ab715a11def..e3139a9a00f 100644 --- a/lib/turbo_tests/base_formatter.rb +++ b/lib/turbo_tests/base_formatter.rb @@ -17,6 +17,35 @@ module TurboTests end end + 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) end end diff --git a/lib/turbo_tests/json_example.rb b/lib/turbo_tests/json_example.rb index 77bbd1b87af..e3eb6e35f4b 100644 --- a/lib/turbo_tests/json_example.rb +++ b/lib/turbo_tests/json_example.rb @@ -19,6 +19,7 @@ module TurboTests extra_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.rb index 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_errors lines << "~~~~~~~ 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| end end + 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 backend Scheduler::Defer.do_all_work # Process everything that was added to the defer queue when running the test