Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tech task] Support system specs in docker #3884

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,8 @@
end

create_table "scishield_trainings", charset: "utf8mb3", force: :cascade do |t|
t.integer "user_id"
t.string "course_name"
t.integer "user_id", null: false
t.string "course_name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
context: .
# To debug Github Actions CI issues:
# 1) Replace `target: develop` with `dockerfile: Dockerfile.github-actions`,
# 2) Update the `command:` (for example `command: cd app && bundle install && bundle exec rake teaspoon`)
# 2) Update the `command:` (for example `command: bash -c "cd app && bundle install && bundle exec rake teaspoon"`)
# 3) Run `docker compose build app`.
# 4) Re-run as needed ot attach to the container to run other debugging commands
target: develop
Expand All @@ -29,7 +29,7 @@ services:
- SELENIUM_HOST=selenium
- SELENIUM_PORT=4444
- TEST_APP_PORT=3000
- DOCKER=true
- DOCKER_LOCAL_DEV=true
# Uncomment below to run teaspoon tests
# - RAILS_ENV=test
# - TEASPOON_RAILS_ENV=test
Expand Down Expand Up @@ -78,7 +78,7 @@ services:
stdin_open: true
# For system-tests and teaspoon
selenium:
image: selenium/standalone-chrome-debug
image: selenium/standalone-chrome:119.0.6045.199-chromedriver-119.0.6045.105
logging:
driver: none
ports:
Expand Down
27 changes: 18 additions & 9 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@
end

config.before(:each, type: :system, js: true) do
if ENV["DOCKER"]
if ENV["DOCKER_LOCAL_DEV"]
Capybara.register_driver :selenium_remote do |app|
options = { url: "http://chrome:4444/wd/hub",
browser: :chrome,
options: [:chrome]
}
Capybara::Selenium::Driver.new(app, options)
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument("--headless")
options.add_argument("--window-size=1366,768")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
Capybara::Selenium::Driver.new(app,
browser: :remote,
url: "http://selenium:4444/wd/hub",
options:)

end

driven_by(:selenium_remote)
Expand All @@ -61,7 +67,7 @@
# Gives more verbose output for JS errors, fails any spec with SEVERE errors
# Based on https://medium.com/@coorasse/catch-javascript-errors-in-your-system-tests-89c2fe6773b1
config.after(:each, type: :system, js: true) do |example|
unless ENV['DOCKER']
unless ENV["DOCKER_LOCAL_DEV"]
# Must call page.driver.browser.logs.get(:browser) after every run,
# otherwise the logs don't get cleared and leak into other specs.
js_errors = page.driver.browser.logs.get(:browser)
Expand Down Expand Up @@ -162,9 +168,12 @@

# Javascript specs need to be able to talk to localhost
config.around(:each, :js) do |example|
if ENV["DOCKER"]
WebMock.allow_net_connect!
if ENV["DOCKER_LOCAL_DEV"]
# As a workaround for https://github.com/bblimke/webmock/issues/1014,
# we disable WebMock completely for specs run locally within docker.
WebMock.disable!
example.call
WebMock.enable!
WebMock.disable_net_connect!
else
WebMock.disable_net_connect!(allow_localhost: true)
Expand Down