Skip to content

Commit

Permalink
Fix WEBPACKER_PRECOMPILE value symmetry and improve test coverage (sh…
Browse files Browse the repository at this point in the history
  • Loading branch information
ur5us authored Aug 12, 2022
1 parent 4bbb4a9 commit f0f1cb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/webpacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def ensure_consistent_versioning?
def webpacker_precompile?
# ENV of false takes precedence
return false if %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
return true if %w(yes true t).include?(ENV["WEBPACKER_PRECOMPILE"])
return true if %w(yes true y t).include?(ENV["WEBPACKER_PRECOMPILE"])

return false unless config_path.exist?
fetch(:webpacker_precompile)
Expand Down
26 changes: 25 additions & 1 deletion test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,28 @@ def test_ensure_consistent_versioning?
def test_webpacker_precompile
assert @config.webpacker_precompile?

ENV["WEBPACKER_PRECOMPILE"] = "no"
refute Webpacker.config.webpacker_precompile?

ENV["WEBPACKER_PRECOMPILE"] = "yes"
assert Webpacker.config.webpacker_precompile?

ENV["WEBPACKER_PRECOMPILE"] = "false"
refute Webpacker.config.webpacker_precompile?

ENV["WEBPACKER_PRECOMPILE"] = "true"
assert Webpacker.config.webpacker_precompile?

ENV["WEBPACKER_PRECOMPILE"] = "n"
refute Webpacker.config.webpacker_precompile?

ENV["WEBPACKER_PRECOMPILE"] = "yes"
ENV["WEBPACKER_PRECOMPILE"] = "y"
assert Webpacker.config.webpacker_precompile?

ENV["WEBPACKER_PRECOMPILE"] = "f"
refute Webpacker.config.webpacker_precompile?

ENV["WEBPACKER_PRECOMPILE"] = "t"
assert Webpacker.config.webpacker_precompile?

@no_precompile_config = Webpacker::Configuration.new(
Expand All @@ -136,6 +152,14 @@ def test_webpacker_precompile
ENV["WEBPACKER_PRECOMPILE"] = nil

refute @no_precompile_config.webpacker_precompile?

@invalid_path_config = Webpacker::Configuration.new(
root_path: @config.root_path,
config_path: Pathname.new(File.expand_path("./test_app/config/invalid_path.yml", __dir__)),
env: "default"
)

refute @invalid_path_config.webpacker_precompile?
end

def test_fall_back_to_bundled_config_with_the_same_name_for_standard_environments
Expand Down

0 comments on commit f0f1cb5

Please sign in to comment.