Skip to content

Commit

Permalink
fix: load initializers.rb instead of require for working tests (#700)
Browse files Browse the repository at this point in the history
* fix: load `initializers.rb` instead of require for working tests

* fix cop
  • Loading branch information
jaredcwhite authored Jan 24, 2023
1 parent 4359adb commit 4b7b90f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def run_initializers!(context:) # rubocop:todo Metrics/AbcSize, Metrics/Cyclomat
initializers_file = File.join(root_dir, "config", "initializers.rb")
return unless File.file?(initializers_file)

require initializers_file
load initializers_file

return unless initializers # no initializers have been set up

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _setup_initializer(name:, require_gem:, require_initializer:)

if require_initializer
init_file_name = File.join(@scope.root_dir, "config", "#{name}.rb")
require(init_file_name) if File.exist?(init_file_name)
load(init_file_name) if File.exist?(init_file_name)
end

@scope.initializers[name.to_sym]
Expand Down
10 changes: 4 additions & 6 deletions bridgetown-core/test/ssr/config/initializers.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# frozen_string_literal: true

Bridgetown.configure do
init :ssr do
setup ->(site) do
site.data.iterations ||= 0
site.data.iterations += 1
end
end
# attempt multiple inits just to ensure it is idempotent
init :local_ssr_init, require_gem: false
init :local_ssr_init, require_gem: false
init :local_ssr_init, require_gem: false
end
10 changes: 10 additions & 0 deletions bridgetown-core/test/ssr/config/local_ssr_init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

Bridgetown.initializer :local_ssr_init do |config|
config.init :ssr do
setup ->(site) do
site.data.iterations ||= 0
site.data.iterations += 1
end
end
end

0 comments on commit 4b7b90f

Please sign in to comment.