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

fix: load initializers.rb instead of require for working tests #700

Merged
merged 2 commits into from
Jan 24, 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
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