Skip to content

Commit

Permalink
attempt to support both 3.0.1 & 3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Judahmeek committed Oct 17, 2017
1 parent c1d0a8b commit e16c840
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def self.using_webpacker?
end

def self.bundle_js_file_path_from_webpacker(bundle_name)
hashed_bundle_name = Webpacker.manifest.lookup!(bundle_name)
possible_result = Webpacker.manifest.lookup(bundle_name)
hashed_bundle_name = possible_result.nil? ? Webpacker.manifest.lookup!(bundle_name) : possible_result
if Webpacker.dev_server.running?
result = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
result
Expand Down
23 changes: 21 additions & 2 deletions spec/react_on_rails/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module ReactOnRails
.and_return(false)
allow(Webpacker).to receive_message_chain("config.public_output_path")
.and_return("/webpack/development")
allow(Webpacker).to receive_message_chain("manifest.lookup!")
allow(Webpacker).to receive_message_chain("manifest.lookup")
.with("webpack-bundle.js")
.and_return("/webpack/development/webpack-bundle-0123456789abcdef.js")
allow(Utils).to receive(:using_webpacker?).and_return(true)
Expand All @@ -42,13 +42,32 @@ module ReactOnRails
Utils.server_bundle_js_file_path
end

context "With Webpacker enabled and server file not in manifest", :webpacker do
context "With Webpacker 3.0.1 enabled and server file not in manifest", :webpacker do
before do
allow(Rails).to receive(:root).and_return(Pathname.new("."))
allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_js_file")
.and_return("webpack-bundle.js")
allow(Webpacker).to receive_message_chain("config.public_output_path")
.and_return("public/webpack/development")
allow(Webpacker).to receive_message_chain("manifest.lookup")
.with("webpack-bundle.js")
.and_raise(Webpacker::Manifest::MissingEntryError)
allow(Utils).to receive(:using_webpacker?).and_return(true)
end

it { expect(subject).to eq("public/webpack/development/webpack-bundle.js") }
end

context "With Webpacker 3.0.2 enabled and server file not in manifest", :webpacker do
before do
allow(Rails).to receive(:root).and_return(Pathname.new("."))
allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_js_file")
.and_return("webpack-bundle.js")
allow(Webpacker).to receive_message_chain("config.public_output_path")
.and_return("public/webpack/development")
allow(Webpacker).to receive_message_chain("manifest.lookup")
.with("webpack-bundle.js")
.and_return(nil)
allow(Webpacker).to receive_message_chain("manifest.lookup!")
.with("webpack-bundle.js")
.and_raise(Webpacker::Manifest::MissingEntryError)
Expand Down

0 comments on commit e16c840

Please sign in to comment.