Skip to content

Instantly share code, notes, and snippets.

@bbonamin
Created April 20, 2022 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbonamin/c8911c401c2808387f34df70fbaf68df to your computer and use it in GitHub Desktop.
Save bbonamin/c8911c401c2808387f34df70fbaf68df to your computer and use it in GitHub Desktop.
Rails 7 + esbuild + minitest + system tests with Bitbucket Pipelines
# test/application_system_test_case.rb
require "test_helper"
require "vcr"
require "webdrivers" unless ENV["CI"]
driver_hosts = if defined?(Webdrivers)
Webdrivers::Common.subclasses.map { |driver| URI(driver.base_url).host }
end
VCR.configure do |config|
config.cassette_library_dir = "vcr_cassettes"
config.hook_into :webmock
config.ignore_localhost = true
config.ignore_hosts(*driver_hosts) if defined?(Webdrivers)
end
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
if ENV["CI"]
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400], options: {url: "http://localhost:4444/wd/hub"}
else
driven_by :selenium, using: (ENV["GUI"] ? :chrome : :headless_chrome), screen_size: [1400, 1400]
end
end
image: cimg/ruby:3.1.2-browsers
pipelines:
default:
- parallel:
- step:
name: Test
caches:
- bundler
- node
script:
- cp config/database.pipelines.yml config/database.yml
- bundle exec rails db:migrate
- bundle exec rails test:system test
services:
- postgres
- selenium-chrome
- step:
name: Lint code
caches:
- bundler
script:
- bundle install
- bundle exec standardrb
definitions:
caches:
bundler: vendor/bundle
services:
postgres:
image: postgres
variables:
POSTGRES_DB: "testdb"
POSTGRES_USER: "testuser"
POSTGRES_PASSWORD: "password"
selenium-chrome:
image: selenium/standalone-chrome:100.0
ports:
- "4444:4444"
# config/database.pipelines.yml
test:
adapter: postgresql
encoding: unicode
host: localhost
port: 5432
username: testuser
password: password
database: testdb
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
# ...
group :test do
gem "capybara"
gem "selenium-webdriver"
gem "vcr"
# Easy installation and use of web drivers to run system tests with browsers
gem "webdrivers", require: !ENV["CI"]
end
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment