Skip to content

Commit

Permalink
Add a separate test run for testing code-reloading
Browse files Browse the repository at this point in the history
simplecov is incompatible with code
reloads (simplecov-ruby/simplecov#389), so
trying to add `cache_classes = false` to our regular test runs results
in broken coverage reports.
  • Loading branch information
jdelStrother committed May 13, 2023
1 parent 8d093e3 commit e0c981d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ jobs:
run: |
bundle config path vendor/bundle
bundle update
bundle exec rake test spec
# Code-reloading isn't compatible with simplecov, so we need to run once
# to collect coverage, and again to test reloads.
MEASURE_COVERAGE=true bundle exec rake test spec
ENABLE_RELOADING=true bundle exec rake test spec
env:
RAISE_ON_WARNING: 1
MEASURE_COVERAGE: true
RAILS_VERSION: ${{ matrix.rails_version }}
CAPTURE_PATCH_ENABLED: ${{ matrix.mode == 'capture_patch_enabled' && 'true' || 'false' }}
- name: Upload coverage results
Expand Down
5 changes: 3 additions & 2 deletions test/sandbox/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!

# `cache_classes=false` is necessary to test code-reloading for people using VC in development
config.cache_classes = false
# `cache_classes=false` is necessary to test code-reloading for people using VC in development.
# However, it's incompatible with collecting simplecov coverage reports.
config.cache_classes = !ENV["ENABLE_RELOADING"]

# Show full error reports and disable caching
config.consider_all_requests_local = true
Expand Down
4 changes: 4 additions & 0 deletions test/sandbox/test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def test_inherited_component_with_call_method_does_not_recompile_superclass
end

def test_helper_changes_are_reflected_on_new_request
skip if Rails.application.config.cache_classes

get "/helpers_proxy_component"
assert_select("div", "Hello helper method")
assert_response :success
Expand All @@ -151,6 +153,8 @@ def message
end

def test_helper_changes_are_reflected_on_new_request_with_previews
skip if Rails.application.config.cache_classes

with_preview_route("/previews") do
get "/previews/helpers_proxy_component/default"
assert_select("div", "Hello helper method")
Expand Down
12 changes: 8 additions & 4 deletions test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,18 @@ def test_validations_component
end

def test_compiles_unrendered_component
skip "this might not still be compiled if it's been reloaded since boot"
# The UnreferencedComponent will get compiled at boot,
# but that might have been thrown away if code-reloading is enabled
skip unless Rails.env.cache_classes?

assert UnreferencedComponent.compiled?
# Or a possible alternative is booting a fresh process:
# assert_equal "true\n", `ruby -r bundler/setup -r ./test/sandbox/config/environment.rb -e "puts UnreferencedComponent.compiled?"`
end

def test_compiles_components_without_initializers
MissingInitializerComponent.compile
# MissingInitializerComponent will get compiled at boot,
# but that might have been thrown away if code-reloading is enabled
skip unless Rails.env.cache_classes?

assert MissingInitializerComponent.compiled?
end

Expand Down

0 comments on commit e0c981d

Please sign in to comment.