browser_errors.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. module BrowserErrorsHelpers
  3. def ignore_js_error(error)
  4. @ignored_js_errors_for_spec << error
  5. end
  6. end
  7. RSpec.configure do |config|
  8. config.include BrowserErrorsHelpers, :js, type: :system
  9. config.before(:each, :js, type: :system) do
  10. @ignored_js_errors_for_spec = []
  11. end
  12. config.after(:each, :js, type: :system) do
  13. # Classes of intermittent ignorable errors
  14. ignored_errors = [
  15. /Error while trying to use the following icon from the Manifest/, # https://github.com/mastodon/mastodon/pull/30793
  16. /Manifest: Line: 1, column: 1, Syntax error/, # Similar parsing/interruption issue as above
  17. ].concat(@ignored_js_errors_for_spec)
  18. errors = page.driver.browser.logs.get(:browser).reject do |error|
  19. ignored_errors.any? { |pattern| pattern.match(error.message) }
  20. end
  21. if errors.present?
  22. aggregate_failures 'browser errrors' do
  23. errors.each do |error|
  24. expect(error.level).to_not eq('SEVERE'), error.message
  25. next unless error.level == 'WARNING'
  26. warn 'WARN: browser warning'
  27. warn error.message
  28. end
  29. end
  30. end
  31. end
  32. end