From df9e220364484acccdb3f51b71a7081dfa0bec2f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 12 Jan 2024 04:12:31 -0500 Subject: [PATCH] Add JS console errors check (#28682) --- lib/tasks/spec.rake | 2 ++ spec/support/javascript_errors.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 spec/support/javascript_errors.rb diff --git a/lib/tasks/spec.rake b/lib/tasks/spec.rake index 8f2cbeea358..d505a471953 100644 --- a/lib/tasks/spec.rake +++ b/lib/tasks/spec.rake @@ -3,6 +3,8 @@ if Rake::Task.task_defined?('spec:system') namespace :spec do task :enable_system_specs do # rubocop:disable Rails/RakeEnvironment + ENV['LOCAL_DOMAIN'] = 'localhost:3000' + ENV['LOCAL_HTTPS'] = 'false' ENV['RUN_SYSTEM_SPECS'] = 'true' end end diff --git a/spec/support/javascript_errors.rb b/spec/support/javascript_errors.rb new file mode 100644 index 00000000000..bdce1cc76db --- /dev/null +++ b/spec/support/javascript_errors.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.after(:each, type: :system) do + errors = page.driver.browser.logs.get(:browser) + if errors.present? + aggregate_failures 'javascript errrors' do + errors.each do |error| + expect(error.level).to_not eq('SEVERE'), error.message + next unless error.level == 'WARNING' + + $stderr.warn 'WARN: javascript warning' + $stderr.warn error.message + end + end + end + end +end