Created
October 12, 2022 21:20
-
-
Save ndbroadbent/e850ec4bb37d79b4571c311d104da39b to your computer and use it in GitHub Desktop.
Configure RSpec to crash on any JS errors or warnings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired by https://medium.com/@coorasse/catch-javascript-errors-in-your-system-tests-89c2fe6773b1 | |
IGNORED_BROWSER_LOGS = [ | |
'You may test your Stripe.js integration over HTTP. However, live Stripe.js integrations must use HTTPS.', | |
].freeze | |
RSpec.configure do |config| | |
config.after :each, js: true do | |
errors = page.driver.browser.manage.logs.get(:browser) | |
next if errors.blank? | |
aggregate_failures 'Browser Errors' do | |
errors.each do |error| | |
next unless %w[WARNING SEVERE].include?(error.level) | |
next if IGNORED_BROWSER_LOGS.any? { |msg| error.message.include?(msg) } | |
flunk "[Browser Logs] #{error.level}: #{error.message}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment